]> _ Git - pmi.git/commitdiff
wip #6245 @1:00
authorsoufiane <soufiane@cubedesigners.com>
Tue, 5 Sep 2023 16:40:40 +0000 (18:40 +0200)
committersoufiane <soufiane@cubedesigners.com>
Tue, 5 Sep 2023 16:40:40 +0000 (18:40 +0200)
app/Models/ECommerceCommon.php
resources/views/components/item-cart.blade.php

index 24aee78cd535d2b2e93a92176b1c47e2c82a3dcb..e2aa2913424f74c91e6b010b708a3ca7a949657f 100644 (file)
@@ -3,6 +3,7 @@
 namespace App\Models;
 
 use Cubist\Backpack\app\Magic\Models\CubistMagicAbstractModel;
+use function GuzzleHttp\Psr7\str;
 
 class ECommerceCommon extends CubistMagicAbstractModel
 {
@@ -59,6 +60,15 @@ class ECommerceCommon extends CubistMagicAbstractModel
         return $totalHT * 0.2;
     }
 
+    public static function formatPrice($price) {
+        $baseFormat = str_replace(",","", $price);
+        $toFloat = floatval($baseFormat);
+        $withDecimal = number_format($toFloat,2);
+        $withoutComma = str_replace(",","",$withDecimal);
+        $pointToComma = str_replace(".",",", $withoutComma);
+        return str_replace(" ","",$pointToComma);
+    }
+
     public static function updateCartData($currentCartRef,$data = [], $productsInfosBase = []) {
         $opt = [];
         $total = [];
index 8c639610787a5c3cce63395fd22d2ba7afd2c219..c1dc1bf7d4999541bc77b493278d43b0b394fb50 100644 (file)
                                     <p class="no-m">{{ __('Prix catalogue') }} :
                                         <span class="text-navy line-through">
                                             @if(floatval($product['price']))
-                                                {{ $product['price'] }}
+                                                {{ \App\Models\ECommerceCommon::formatPrice($product['price']) }}
                                             @else
-                                                {{ $product['basic_selling_price'] }}
+                                                {{ \App\Models\ECommerceCommon::formatPrice($product['basic_selling_price']) }}
                                             @endif € HT
                                         </span>
                                     </p>
                                     <p class="no-m">{{ __('Votre prix') }} :
                                         <span class="text-navy">
                                             @if(floatval($product['price']))
-                                                {{ $product['price'] - (($product['price'] * $product['discount']) / 100) }}
+                                                {{ \App\Models\ECommerceCommon::formatPrice($product['price'] - (($product['price'] * $product['discount']) / 100)) }}
                                             @else
-                                                {{ number_format($product['basic_selling_price'] - (($product['basic_selling_price'] * $product['discount']) / 100), 2) }}
+                                                {{ \App\Models\ECommerceCommon::formatPrice($product['basic_selling_price'] - (($product['basic_selling_price'] * $product['discount']) / 100)) }}
                                             @endif € HT
                                         </span>
                                     </p>
@@ -49,9 +49,9 @@
                                         <p class="no-m">{{ __('Prix unitaire') }} :
                                             <span class="text-navy">
                                                 @if(floatval($product['price']))
-                                                    {{ $product['price'] - (($product['price'] * $product['discount']) / 100) }}
+                                                    {{ \App\Models\ECommerceCommon::formatPrice($product['price'] - (($product['price'] * $product['discount']) / 100)) }}
                                                 @else
-                                                    {{ $product['basic_selling_price'] }}
+                                                    {{ \App\Models\ECommerceCommon::formatPrice(['basic_selling_price']) }}
                                                 @endif € HT
                                             </span>
                                         </p>
@@ -65,7 +65,7 @@
                                 @php($price = $product['price'] - (($product['price'] * $product['discount']) / 100))
                                 <p class="no-m">
                                     <span class="sm:inline hidden">{{ __('Total HT : ') }}</span>
-                                    {{ $price * $product['quantity'] }}€ HT
+                                    {{ \App\Models\ECommerceCommon::formatPrice($price * $product['quantity']) }}€ HT
                                 </p>
                             @else
                                 <p class="text-navy">
@@ -85,9 +85,9 @@
                 @if($item['total'])
                     <div class="text-right pb-6">
                         <p class="no-m">{{ __('Frais de port HT') }} : {{ $prices < 1000 ? 20 : 0 }}€</p>
-                        <p class="no-m">{{ __('Total HT') }} : {{ $prices += ($prices < 1000 ? 20 : 0) }}€</p>
-                        <p class="no-m">{{ __('Montant TVA') }} : {{ $prices * 0.2 }}€</p>
-                        <p class="no-m">{{ __('Total TTC') }} : {{ $item['total'] }}€</p>
+                        <p class="no-m">{{ __('Total HT') }} : {{ \App\Models\ECommerceCommon::formatPrice($prices += ($prices < 1000 ? 20 : 0)) }}€</p>
+                        <p class="no-m">{{ __('Montant TVA') }} : {{ \App\Models\ECommerceCommon::formatPrice($prices * 0.2) }}€</p>
+                        <p class="no-m">{{ __('Total TTC') }} : {{ \App\Models\ECommerceCommon::formatPrice($item['total']) }}€</p>
                     </div>
                 @endif
             </div>