Display a promotion as a badge next to a product name
This commit is contained in:
@@ -120,7 +120,7 @@ class ScrapeWebsite extends Command
|
|||||||
$productModel->lastSeen = date("Y-m-d");
|
$productModel->lastSeen = date("Y-m-d");
|
||||||
$productModel->touch('updated_at');
|
$productModel->touch('updated_at');
|
||||||
$productModel->country()->associate($country);
|
$productModel->country()->associate($country);
|
||||||
$productModel->promotions = json_encode($product->promotions);
|
$productModel->promotions = $product->promotions;
|
||||||
$productModel->save();
|
$productModel->save();
|
||||||
$priceExists = $productModel->price()->whereRaw("strftime('%Y-%m-%d', created_at) = ?", [date('Y-m-d')])->exists();
|
$priceExists = $productModel->price()->whereRaw("strftime('%Y-%m-%d', created_at) = ?", [date('Y-m-d')])->exists();
|
||||||
|
|
||||||
|
|||||||
@@ -88,6 +88,13 @@ class Product extends Model
|
|||||||
set: fn(array $value) => json_encode($value),
|
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
|
public function isDiscontinued(): bool
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
<td>
|
<td>
|
||||||
<a href='{{ path('app_product', {'productId': product.id}) }}' class="text-decoration-none">{{ product.name }}</a>
|
<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>
|
<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>
|
||||||
<td>
|
<td>
|
||||||
<nav aria-label="breadcrumb" style="--bs-breadcrumb-divider: '>';">
|
<nav aria-label="breadcrumb" style="--bs-breadcrumb-divider: '>';">
|
||||||
|
|||||||
@@ -49,6 +49,7 @@
|
|||||||
<span class="badge text-bg-light"><a
|
<span class="badge text-bg-light"><a
|
||||||
href="{{ path('app_search', {'search': product.subTitle}) }}"
|
href="{{ path('app_search', {'search': product.subTitle}) }}"
|
||||||
class="link-underline link-underline-opacity-0 link-dark">{{ product.subTitle }}</a></span>
|
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>
|
||||||
<td class="align-middle">
|
<td class="align-middle">
|
||||||
<nav aria-label="breadcrumb" style="--bs-breadcrumb-divider: '>';">
|
<nav aria-label="breadcrumb" style="--bs-breadcrumb-divider: '>';">
|
||||||
|
|||||||
Reference in New Issue
Block a user