diff --git a/app/Models/Product.php b/app/Models/Product.php index 99dc2b74..d806184c 100644 --- a/app/Models/Product.php +++ b/app/Models/Product.php @@ -207,7 +207,17 @@ class Product extends Model implements Buyable if (isset($this->priceKgTtc)) { $showPrice = $this->priceKgTtc; } else { - $priceKgTtc = $this->attributes['price'] * (1 + ($this->tax->rate / 100)); + $discountedPriceKgTtc = $this->price; + if ($this->promotions->count()) { + $applicablePromotion = $this->promotions->first(); + if ($applicablePromotion->discountType->id == 1) { + $discountedPriceKgTtc = $this->price - $applicablePromotion->discount_value; + } else { + $discountedPriceKgTtc = $this->price - ($this->price * $applicablePromotion->discount_value / 100); + } + } + $priceKgTtc = $discountedPriceKgTtc * (1 + ($this->tax->rate / 100)); + /** * On travaille avec des centimes puis on redivise par 100 pour avoir des unités monetaires * on augmente la précision à 3 digits, l'affichage formate les prix sur 2 décimales diff --git a/resources/views/front/sable/home.blade.php b/resources/views/front/sable/home.blade.php index fcbe088d..8c60d15d 100644 --- a/resources/views/front/sable/home.blade.php +++ b/resources/views/front/sable/home.blade.php @@ -28,12 +28,12 @@ {!! $product->description !!}
+
@if ($product->weight_variable) Environ* @endif - @fmt_currency($product->discountedPriceTtc) + @fmt_currency($product->discountedPriceTtc) + @if ($product->promotions->count()) + @fmt_currency_without_ttc($product->priceTtc) + @endif /{{ $product->sell_unit }}
*Produit vendu au kilo : {{ currencyFormatter(product.priceKgTtc) }} /kg
@if ($product->weight_variable) Environ* @endif - @fmt_currency($product->discountedPriceTtc) + @fmt_currency($product->discountedPriceTtc) + @if ($product->promotions->count()) + @fmt_currency($product->priceTtc) + @endif /{{ $product->sell_unit }}