feature/handle-promotions #59

Merged
krzysiej merged 5 commits from feature/handle-promotions into master 2026-02-04 08:35:16 +01:00
4 changed files with 10 additions and 1 deletions
Showing only changes of commit cfb70a365d - Show all commits

View File

@@ -120,7 +120,7 @@ class ScrapeWebsite extends Command
$productModel->lastSeen = date("Y-m-d");
$productModel->touch('updated_at');
$productModel->country()->associate($country);
$productModel->promotions = json_encode($product->promotions);
$productModel->promotions = $product->promotions;
$productModel->save();
$priceExists = $productModel->price()->whereRaw("strftime('%Y-%m-%d', created_at) = ?", [date('Y-m-d')])->exists();

View File

@@ -88,6 +88,13 @@ class Product extends Model
set: fn(array $value) => json_encode($value),
);
}
public function promotions(): Attribute
{
return Attribute::make(
get: fn(?string $value) => json_decode($value ?? '{"hasPromotion": false}', 1),
set: fn(array $value) => json_encode($value),
);
}
public function isDiscontinued(): bool
{

View File

@@ -11,6 +11,7 @@
<td>
<a href='{{ path('app_product', {'productId': product.id}) }}' class="text-decoration-none">{{ product.name }}</a>
<span class="badge text-bg-light"><a href="{{ path('app_search', {'search': product.subTitle}) }}" class="link-underline link-underline-opacity-0 link-dark">{{ product.subTitle }}</a></span>
{% if product.promotions is not null and product.promotions.hasPromotion %}<span class="badge bg-info">PROMO: {{ product.promotions.tag }}</span>{% endif %}
</td>
<td>
<nav aria-label="breadcrumb" style="--bs-breadcrumb-divider: '>';">

View File

@@ -49,6 +49,7 @@
<span class="badge text-bg-light"><a
href="{{ path('app_search', {'search': product.subTitle}) }}"
class="link-underline link-underline-opacity-0 link-dark">{{ product.subTitle }}</a></span>
{% if product.promotions is not null and product.promotions.hasPromotion %}<span class="badge bg-info">PROMO: {{ product.promotions.tag }}</span>{% endif %}
</td>
<td class="align-middle">
<nav aria-label="breadcrumb" style="--bs-breadcrumb-divider: '>';">