Start working on handling multiple countries at once

This commit is contained in:
2026-01-17 09:56:40 +01:00
parent 03b74aa33d
commit 22e4034ae3
4 changed files with 28 additions and 19 deletions

View File

@@ -41,6 +41,7 @@ class Migrate extends Command
$this->createStocksTable(); $this->createStocksTable();
$this->addColumns(); $this->addColumns();
$this->createCountriesTable(); $this->createCountriesTable();
$this->index();
return Command::SUCCESS; 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']);
});
}
} }

View File

@@ -56,16 +56,16 @@ class ScrapeWebsite extends Command
$products = Product::all(); $products = Product::all();
$progress->setMaxSteps(count($products)); $progress->setMaxSteps(count($products));
$progress->start(); $progress->start();
// foreach($products as $product) { foreach($products as $product) {
// $newestPrice = $product->newestPrice; $newestPrice = $product->newestPrice;
// $product->priceCurrent = $newestPrice->price; $product->priceCurrent = $newestPrice->price;
// $product->productStandardPrice = $newestPrice->productStandardPrice; $product->productStandardPrice = $newestPrice->productStandardPrice;
// $product->lowestProductPrice30Days = $newestPrice->lowestProductPrice30Days; $product->lowestProductPrice30Days = $newestPrice->lowestProductPrice30Days;
// $product->priceLowest = $product->lowestPrice->price; $product->priceLowest = $product->lowestPrice->price;
// $product->lastSeen = $newestPrice->created_at->format('Y-m-d'); $product->lastSeen = $newestPrice->created_at->format('Y-m-d');
// $product->save(['timestamps' => false]); $product->save(['timestamps' => false]);
// $progress->advance(); $progress->advance();
// } }
$progress->finish(); $progress->finish();
$output->writeln(''); $output->writeln('');
$output->writeln('Update prices - DONE'); $output->writeln('Update prices - DONE');

View File

@@ -44,9 +44,9 @@
</thead> </thead>
{% for price in product.price %} {% for price in product.price %}
<tr> <tr>
<td>{{ price.price | format_currency('GBP', {}, 'en') }}</td> <td>{{ price.price | format_currency(product.country.currency, {}, product.country.locale) }}</td>
<td>{{ price.lowestProductPrice30Days | format_currency('GBP', {}, 'en') }}</td> <td>{{ price.lowestProductPrice30Days | format_currency(product.country.currency, {}, product.country.locale) }}</td>
<td>{{ price.productStandardPrice | format_currency('PLN', {}, 'pl') }}</td> <td>{{ price.productStandardPrice | format_currency(product.country.currency, {}, product.country.locale) }}</td>
<td>{{ price.created_at }}</td> <td>{{ price.created_at }}</td>
<td>{{ (product.stock | findByCreatedAtDate(price.created_at | slice(0,10))).stock ?? '' }}</td> <td>{{ (product.stock | findByCreatedAtDate(price.created_at | slice(0,10))).stock ?? '' }}</td>
</tr> </tr>
@@ -67,7 +67,7 @@
labels: ['{{ price_dates|raw }}'], labels: ['{{ price_dates|raw }}'],
datasets: [ datasets: [
{ {
label: 'Price (PLN)', label: 'Price ({{ product.country.currency }})',
data: {{ price_list|raw }}, data: {{ price_list|raw }},
yAxisID: 'yPrice', yAxisID: 'yPrice',
tension: 0.1, tension: 0.1,
@@ -99,7 +99,7 @@
beginAtZero: true, beginAtZero: true,
title: { title: {
display: true, display: true,
text: 'Price (PLN)' text: 'Price ({{ product.country.currency }})'
}, },
grid: { grid: {
drawOnChartArea: false drawOnChartArea: false

View File

@@ -48,16 +48,16 @@
<td class="align-middle"><a href='https://pl.ryobitools.eu/{{ product.url }}'>link</a></td> <td class="align-middle"><a href='https://pl.ryobitools.eu/{{ product.url }}'>link</a></td>
<td class="align-middle text-end"> <td class="align-middle text-end">
{% if product.isDiscontinued() or product.priceCurrent == product.productStandardPrice %} {% 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 %} {% else %}
{% if product.priceLowest != product.priceCurrent %}{{ product.priceLowest | format_currency('PLN', {}, 'pl') }}{%else%}<span class="badge text-bg-info">now lowest</span>{% endif %}</td> {% if product.priceLowest != product.priceCurrent %}{{ product.priceLowest | format_currency(product.country.currency, {}, product.country.locale) }}{%else%}<span class="badge text-bg-info">now lowest</span>{% endif %}</td>
{% endif %} {% endif %}
<td class="align-middle text-end">{{ product.priceCurrent | format_currency('PLN', {}, 'pl') }}</td> <td class="align-middle text-end">{{ product.priceCurrent | format_currency(product.country.currency, {}, product.country.locale) }}</td>
<td class="align-middle"> <td class="align-middle">
<div class="d-flex flex-row"> <div class="d-flex flex-row">
{% if product.priceCurrent != product.productStandardPrice %}<span {% if product.priceCurrent != product.productStandardPrice %}<span
class="badge text-bg-warning text-decoration-line-through flex-fill">{{ product.productStandardPrice | format_currency('PLN', {}, 'pl') }}</span> <span class="badge text-bg-warning text-decoration-line-through flex-fill">{{ product.productStandardPrice | format_currency(product.country.currency, {}, product.country.locale) }}</span> <span
class="badge text-bg-success flex-fill">{{ ((1 - product.priceCurrent / product.productStandardPrice)*100)|number_format(0) }}%</span> class="badge text-bg-success flex-fill">{{ ((1 - product.priceCurrent / product.productStandardPrice)*100)|number_format(0) }}%</span>
{% endif %} {% endif %}
</div> </div>