feature/handle-multiple-countries #45

Merged
krzysiej merged 5 commits from feature/handle-multiple-countries into master 2026-01-17 17:07:40 +01:00
4 changed files with 28 additions and 19 deletions
Showing only changes of commit 22e4034ae3 - Show all commits

View File

@@ -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']);
});
}
}

View File

@@ -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');

View File

@@ -44,9 +44,9 @@
</thead>
{% for price in product.price %}
<tr>
<td>{{ price.price | format_currency('GBP', {}, 'en') }}</td>
<td>{{ price.lowestProductPrice30Days | format_currency('GBP', {}, 'en') }}</td>
<td>{{ price.productStandardPrice | format_currency('PLN', {}, 'pl') }}</td>
<td>{{ price.price | format_currency(product.country.currency, {}, product.country.locale) }}</td>
<td>{{ price.lowestProductPrice30Days | format_currency(product.country.currency, {}, product.country.locale) }}</td>
<td>{{ price.productStandardPrice | format_currency(product.country.currency, {}, product.country.locale) }}</td>
<td>{{ price.created_at }}</td>
<td>{{ (product.stock | findByCreatedAtDate(price.created_at | slice(0,10))).stock ?? '' }}</td>
</tr>
@@ -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

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 text-end">
{% 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%}<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 %}
<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">
<div class="d-flex flex-row">
{% 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>
{% endif %}
</div>