diff --git a/app/Http/Controllers/Bo/PromotionsController.php b/app/Http/Controllers/Bo/PromotionsController.php index 98e3541..309eccc 100644 --- a/app/Http/Controllers/Bo/PromotionsController.php +++ b/app/Http/Controllers/Bo/PromotionsController.php @@ -49,17 +49,19 @@ class PromotionsController extends Controller 'product_id' => 'required', ]); - $productIds = explode(",", $request->product_id); - $discType = $request->discount_type_id; - $value = $request->discount_value; - $date_start = $request->date_start_date . " " . $request->date_start_time; - $date_end = $request->date_end_date . " " . $request->date_end_time; + $productIds = explode(",", $request->product_id); + $discType = $request->discount_type_id; + $value = $request->discount_value; + $isOldPriceDisplayed = $request->boolean('is_old_price_displayed'); + $date_start = $request->date_start_date . " " . $request->date_start_time; + $date_end = $request->date_end_date . " " . $request->date_end_time; - $promotion = new Promotion(); - $promotion->discount_type_id = $discType; - $promotion->discount_value = $value; - $promotion->date_start = $date_start; - $promotion->date_end = $date_end; + $promotion = new Promotion(); + $promotion->discount_type_id = $discType; + $promotion->discount_value = $value; + $promotion->is_old_price_displayed = $isOldPriceDisplayed; + $promotion->date_start = $date_start; + $promotion->date_end = $date_end; $promotion->save(); // Prise en charge de la liaison avec les produits. @@ -101,16 +103,18 @@ class PromotionsController extends Controller 'product_id' => 'required', ]); - $productIds = explode(",", $request->product_id); - $discType = $request->discount_type_id; - $value = $request->discount_value; - $date_start = $request->date_start_date . " " . $request->date_start_time; - $date_end = $request->date_end_date . " " . $request->date_end_time; + $productIds = explode(",", $request->product_id); + $discType = $request->discount_type_id; + $value = $request->discount_value; + $isOldPriceDisplayed = $request->boolean('is_old_price_displayed'); + $date_start = $request->date_start_date . " " . $request->date_start_time; + $date_end = $request->date_end_date . " " . $request->date_end_time; - $promotion->discount_type_id = $discType; - $promotion->discount_value = $value; - $promotion->date_start = $date_start; - $promotion->date_end = $date_end; + $promotion->discount_type_id = $discType; + $promotion->discount_value = $value; + $promotion->is_old_price_displayed = $isOldPriceDisplayed; + $promotion->date_start = $date_start; + $promotion->date_end = $date_end; $promotion->save(); // Prise en charge de la liaison avec les produits. diff --git a/app/Models/Promotion.php b/app/Models/Promotion.php index 648ee3f..914e830 100644 --- a/app/Models/Promotion.php +++ b/app/Models/Promotion.php @@ -15,8 +15,9 @@ class Promotion extends Model * @var array */ protected $casts = [ - 'date_start' => 'datetime', - 'date_end' => 'datetime', + 'is_old_price_displayed' => 'boolean', + 'date_start' => 'datetime', + 'date_end' => 'datetime', ]; /** diff --git a/database/migrations/2026_02_25_111055_add_boolean_display_old_value_for_promotions_table.php b/database/migrations/2026_02_25_111055_add_boolean_display_old_value_for_promotions_table.php new file mode 100644 index 0000000..80205bd --- /dev/null +++ b/database/migrations/2026_02_25_111055_add_boolean_display_old_value_for_promotions_table.php @@ -0,0 +1,32 @@ +boolean('is_old_price_displayed')->comment('Should the old price be displayed ?')->after('discount_value'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('promotions', function (Blueprint $table) { + $table->dropColumn('is_old_price_displayed'); + }); + } +} diff --git a/resources/views/bo/promotions/create.blade.php b/resources/views/bo/promotions/create.blade.php index 35f1395..73560c1 100644 --- a/resources/views/bo/promotions/create.blade.php +++ b/resources/views/bo/promotions/create.blade.php @@ -40,7 +40,17 @@
@if ($product->weight_variable) Environ* @endif @fmt_currency($product->discountedPriceTtc) - @if ($product->promotions->count()) + @if ($product->promotions->count() && $product->promotions()->first()->is_old_price_displayed) @fmt_currency_without_ttc($product->priceTtc) @endif /{{ $product->sell_unit }} diff --git a/resources/views/front/sable/js/components/FilterComponent.vue b/resources/views/front/sable/js/components/FilterComponent.vue index 46efd55..643dd14 100644 --- a/resources/views/front/sable/js/components/FilterComponent.vue +++ b/resources/views/front/sable/js/components/FilterComponent.vue @@ -138,7 +138,11 @@
*Produit vendu au kilo : {{ currencyFormatter(product.priceKgTtc) }} /kg
@@ -217,6 +221,12 @@ this.tags = jsonData.tags ?? []; this.search = jsonData.search ?? ""; this.products = jsonData.products ?? []; + console.log(this.products); + for (const product of this.products) { + console.log(product.promotion); + console.log(product.promotion ? product.promotion[0].is_old_price_displayed : 'null'); + console.log(product.promotion ? product.promotion[0].id : 'pas de id'); + } this.productsCount = jsonData.productsCount ?? this.products.length ?? 0; this.productsResults = jsonData.productsResults ?? 0; this.filters = jsonData.filters ?? []; diff --git a/resources/views/front/sable/product.blade.php b/resources/views/front/sable/product.blade.php index 1f58304..797be0e 100644 --- a/resources/views/front/sable/product.blade.php +++ b/resources/views/front/sable/product.blade.php @@ -47,7 +47,7 @@@if ($product->weight_variable) Environ* @endif @fmt_currency($product->discountedPriceTtc) - @if ($product->promotions->count()) + @if ($product->promotions->count() && $product->promotions()->first()->is_old_price_displayed) @fmt_currency($product->priceTtc) @endif /{{ $product->sell_unit }}