feat: added boolean to show old price on discounts - #95

This commit is contained in:
Noah Lancien 2026-02-25 15:27:24 +01:00
parent f9e0448fb6
commit 06785a3cb8
9 changed files with 96 additions and 26 deletions

View file

@ -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.

View file

@ -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',
];
/**

View file

@ -0,0 +1,32 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AddBooleanDisplayOldValueForPromotionsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('promotions', function (Blueprint $table) {
$table->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');
});
}
}

View file

@ -40,7 +40,17 @@
<div class="form-group col">
<label for="discount_value">Valeur *</label>
<input type="number" id="discount_value" name="discount_value" min="0" step=".01" class="form-control" value="{{ old('discount_value') }}" required>
<small class="text-muted"> montant ou pourcentage de remise selon le type choisi </small>
<small class="text-muted"> Montant ou pourcentage de remise selon le type choisi </small>
</div>
<div class="form-group col">
<label for="is_old_price_displayed">Afficher l'ancien prix ?</label>
<input
type="checkbox"
id="is_old_price_displayed"
name="is_old_price_displayed"
class="form-check"
@if(old('is_old_price_displayed', false)) checked @endif>
<small class="text-muted"> Cocher pour afficher l'ancien prix </small>
</div>
<div class="form-group col">
<label for="date_start_date">Début <small class="text-muted"> de la promotion </small></label>

View file

@ -44,7 +44,18 @@
<div class="form-group col">
<label for="discount_value">Valeur *</label>
<input type="number" id="discount_value" name="discount_value" min="0" step=".01" class="form-control" value="{{ old('discount_value',$promotion->discount_value) }}" required>
<small class="text-muted"> montant ou pourcentage de remise selon le type choisi </small>
<small class="text-muted"> Montant ou pourcentage de remise selon le type choisi </small>
</div>
<div class="form-group col">
<label for="is_old_price_displayed">Afficher l'ancien prix ?</label><br>
<input
type="checkbox"
id="is_old_price_displayed"
name="is_old_price_displayed"
class="form-check"
@if(old('is_old_price_displayed', $promotion->is_old_price_displayed)) checked @endif>
<br>
<small class="text-muted"> Cocher pour afficher l'ancien prix </small>
</div>
<div class="form-group col">
<label for="date_start_date">Début <small class="text-muted"> de la promotion </small></label>

View file

@ -15,6 +15,7 @@
<thead>
<th scope="col">Type</th>
<th scope="col">Valeur</th>
<th scope="col">Ancien prix affiché ?</th>
<th scope="col">Début</th>
<th scope="col">Fin</th>
<th scope="col">Produits Concernés</th>
@ -25,6 +26,7 @@
<tr>
<td>{{$promotion->discountType->label}}</td>
<td>{{$promotion->discount_value}}</td>
<td>{{ $promotion->is_old_price_displayed ? 'Oui' : 'Non' }}</td>
<td>{{$promotion->date_start}}</td>
<td>{{$promotion->date_end}}</td>
<td>

View file

@ -31,7 +31,7 @@
<p class="card-price-new">
<span>@if ($product->weight_variable) Environ* @endif</span>
<span class="font-Barlow-bold h4 @if ($product->promotions->count()) text-red @endif">@fmt_currency($product->discountedPriceTtc)</span>
@if ($product->promotions->count())
@if ($product->promotions->count() && $product->promotions()->first()->is_old_price_displayed)
<span class="card-price-original position-relative me-2">@fmt_currency_without_ttc($product->priceTtc)</span>
@endif
<span class="text-lowercase">/{{ $product->sell_unit }}</span>

View file

@ -138,7 +138,11 @@
<div class="card-price d-flex flex-row justify-content-center align-items-center my-2">
<span v-if="product.weight_variable" class="me-1">Environ*</span>
<span class="card-price-new font-Barlow-bold h5" v-bind:class="{'text-red': product.promotion}">{{ currencyFormatter(product.discountedPriceTtc) }}</span>
<span v-if="product.promotion != null" class="card-price-original position-relative m-0 ms-2 m-lg-0 me-lg-2">{{ currencyFormatter(product.priceTtc) }}</span>
<span
v-if="product.promotion != null && product.promotion[0].is_old_price_displayed"
class="card-price-original position-relative m-0 ms-2 m-lg-0 me-lg-2">
{{ currencyFormatter(product.priceTtc) }}
</span>
<span class="text-lowercase ms-1">/{{ product.sell_unit }}</span>
</div>
<p class="fst-italic text-muted mb-2" v-if="product.weight_variable">*Produit vendu au kilo : {{ currencyFormatter(product.priceKgTtc) }} /kg</p>
@ -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 ?? [];

View file

@ -47,7 +47,7 @@
<p class="m-0">
<span>@if ($product->weight_variable) Environ* @endif</span>
<span class="@if ($product->promotions->count()) card-price-new @endif font-Barlow-bold h4 ms-1">@fmt_currency($product->discountedPriceTtc)</span>
@if ($product->promotions->count())
@if ($product->promotions->count() && $product->promotions()->first()->is_old_price_displayed)
<span class="card-price-original position-relative m-0 ms-2 m-lg-0 me-lg-2">@fmt_currency($product->priceTtc)</span>
@endif
<span class="text-lowercase">/{{ $product->sell_unit }}</span>