diff --git a/src/Command/Migrate.php b/src/Command/Migrate.php
index 2372646..96880d5 100644
--- a/src/Command/Migrate.php
+++ b/src/Command/Migrate.php
@@ -41,6 +41,7 @@ class Migrate extends Command
$this->createStocksTable();
$this->addColumns();
$this->createCountriesTable();
+ $this->index();
return Command::SUCCESS;
}
@@ -170,4 +171,12 @@ class Migrate extends Command
});
}
}
+
+ public function index(): void
+ {
+ Capsule::schema()->table('products', function (Blueprint $table) {
+ $table->integer('skuID')->unique(false)->change();
+ $table->unique(['skuID', 'country_id']);
+ });
+ }
}
diff --git a/src/Command/ScrapeWebsite.php b/src/Command/ScrapeWebsite.php
index 5073c6a..9993707 100644
--- a/src/Command/ScrapeWebsite.php
+++ b/src/Command/ScrapeWebsite.php
@@ -56,16 +56,16 @@ class ScrapeWebsite extends Command
$products = Product::all();
$progress->setMaxSteps(count($products));
$progress->start();
-// foreach($products as $product) {
-// $newestPrice = $product->newestPrice;
-// $product->priceCurrent = $newestPrice->price;
-// $product->productStandardPrice = $newestPrice->productStandardPrice;
-// $product->lowestProductPrice30Days = $newestPrice->lowestProductPrice30Days;
-// $product->priceLowest = $product->lowestPrice->price;
-// $product->lastSeen = $newestPrice->created_at->format('Y-m-d');
-// $product->save(['timestamps' => false]);
-// $progress->advance();
-// }
+ foreach($products as $product) {
+ $newestPrice = $product->newestPrice;
+ $product->priceCurrent = $newestPrice->price;
+ $product->productStandardPrice = $newestPrice->productStandardPrice;
+ $product->lowestProductPrice30Days = $newestPrice->lowestProductPrice30Days;
+ $product->priceLowest = $product->lowestPrice->price;
+ $product->lastSeen = $newestPrice->created_at->format('Y-m-d');
+ $product->save(['timestamps' => false]);
+ $progress->advance();
+ }
$progress->finish();
$output->writeln('');
$output->writeln('Update prices - DONE');
diff --git a/templates/product.html.twig b/templates/product.html.twig
index 3a30678..a6ce4dc 100644
--- a/templates/product.html.twig
+++ b/templates/product.html.twig
@@ -44,9 +44,9 @@
{% for price in product.price %}
- | {{ price.price | format_currency('GBP', {}, 'en') }} |
- {{ price.lowestProductPrice30Days | format_currency('GBP', {}, 'en') }} |
- {{ price.productStandardPrice | format_currency('PLN', {}, 'pl') }} |
+ {{ price.price | format_currency(product.country.currency, {}, product.country.locale) }} |
+ {{ price.lowestProductPrice30Days | format_currency(product.country.currency, {}, product.country.locale) }} |
+ {{ price.productStandardPrice | format_currency(product.country.currency, {}, product.country.locale) }} |
{{ price.created_at }} |
{{ (product.stock | findByCreatedAtDate(price.created_at | slice(0,10))).stock ?? '' }} |
@@ -67,7 +67,7 @@
labels: ['{{ price_dates|raw }}'],
datasets: [
{
- label: 'Price (PLN)',
+ label: 'Price ({{ product.country.currency }})',
data: {{ price_list|raw }},
yAxisID: 'yPrice',
tension: 0.1,
@@ -99,7 +99,7 @@
beginAtZero: true,
title: {
display: true,
- text: 'Price (PLN)'
+ text: 'Price ({{ product.country.currency }})'
},
grid: {
drawOnChartArea: false
diff --git a/templates/productList.html.twig b/templates/productList.html.twig
index 0fe850e..9aad00d 100644
--- a/templates/productList.html.twig
+++ b/templates/productList.html.twig
@@ -48,16 +48,16 @@
link |
{% if product.isDiscontinued() or product.priceCurrent == product.productStandardPrice %}
- {{ product.priceLowest | format_currency('PLN', {}, 'pl') }}
+ {{ product.priceLowest | format_currency(product.country.currency, {}, product.country.locale) }}
{% else %}
- {% if product.priceLowest != product.priceCurrent %}{{ product.priceLowest | format_currency('PLN', {}, 'pl') }}{%else%}now lowest{% endif %} |
+ {% if product.priceLowest != product.priceCurrent %}{{ product.priceLowest | format_currency(product.country.currency, {}, product.country.locale) }}{%else%}now lowest{% endif %}
{% endif %}
- {{ product.priceCurrent | format_currency('PLN', {}, 'pl') }} |
+ {{ product.priceCurrent | format_currency(product.country.currency, {}, product.country.locale) }} |
{% if product.priceCurrent != product.productStandardPrice %}{{ product.productStandardPrice | format_currency('PLN', {}, 'pl') }} {{ product.productStandardPrice | format_currency(product.country.currency, {}, product.country.locale) }} {{ ((1 - product.priceCurrent / product.productStandardPrice)*100)|number_format(0) }}%
{% endif %}
|