]> _ Git - pmi.git/commitdiff
wait #6245 @3:05
authorsoufiane <soufiane@cubedesigners.com>
Wed, 6 Sep 2023 13:05:08 +0000 (15:05 +0200)
committersoufiane <soufiane@cubedesigners.com>
Wed, 6 Sep 2023 13:05:08 +0000 (15:05 +0200)
app/Http/Controllers/AjaxController.php
resources/js/app.js
resources/js/components/CartItem.vue
resources/views/components/item-cart-order.blade.php
resources/views/components/item-cart.blade.php
resources/views/pages/order.blade.php
resources/views/pages/product-detail.blade.php
resources/views/partials/header.blade.php
resources/views/partials/product-link.blade.php

index 2d359346df2d7f2561dd7257e5da1317688eb40c..b518d62ea9c874345d9a89eef02cbf372fd94cd7 100644 (file)
@@ -304,9 +304,12 @@ class AjaxController extends CubistFrontController
         $indexMessage = 0;
         $prices = [];
 
+        //dd($cartData,$cartData_);
+
         foreach ($cartData as $id => $_data) {
             $indexMessage++;
-            $optionsPrices = Product::optionPrice($id, $cartData_[$index]['ref'], $productsArray, true);
+            $cartByID = array_values(array_filter($cartData_, function($n) use($id) { return $n['id'] == $id; }));
+            $optionsPrices = Product::optionPrice($id, $cartByID[0]['ref'], $productsArray, true);
             $basicSellingPrice = $products[$id]['basic_selling_price'];
             $categoryProduct = $products[$id]['category'];
             $discount = intval(Client::getDiscount($categoryProduct, Client::getCategory()));
@@ -316,24 +319,22 @@ class AjaxController extends CubistFrontController
                 $price = $basicSellingPrice;
 
                 if ($optionsPrices) {
-                    $totalOptionPrice = Product::totalOptionPrice($optionsPrices[0], $cartData_[$index]['ref']);
+                    $totalOptionPrice = Product::totalOptionPrice($optionsPrices[0], $cartByID[0]['ref']);
                     $price = intval($price) + $totalOptionPrice;
                 }
                 $priceDiscount = ECommerceCommon::priceWithDiscount(floatval($price), $discount);
                 $prices[] = ECommerceCommon::priceWithDiscount(floatval($price * $_data), $discount);
             }
 
-            $pr_cart_data = array_values(array_filter($cartData_, function($n) use($id) { return $n['id'] === $id; }))[0];
-
             $data['products'][] = [
                 'id' => $id,
-                'reference' => (empty($pr_cart_data['ref']) ? $pr_cart_data['reference'] : $pr_cart_data['ref']),
+                'reference' => (empty($cartByID[0]['ref']) ? $cartByID[0]['reference'] : $cartByID[0]['ref']),
                 'name' => $products[$id]['name'],
                 'quantity' => $_data,
                 'price' => isset($price) && intval($price) > 0 && Client::getClientConnected() ? ECommerceCommon::priceWithDiscount($price, $discount)."€" : 0
             ];
 
-            $productsMessage[] = 'Référence : ' . (empty($cartData_[$index]['ref']) ? $cartData_[$index]['reference'] : $cartData_[$index]['ref']) . "\n";
+            $productsMessage[] = 'Référence : ' . (empty($cartByID[0]['ref']) ? $cartByID[0]['reference'] : $cartByID[0]['ref']) . "\n";
             $productsMessage[$indexMessage] .= url("/{$products[$id]['slug']}")."\n";
 
             if(Client::getClientConnected()) {
@@ -341,7 +342,7 @@ class AjaxController extends CubistFrontController
                 $labelPriceDiscount = 'Prix unitaire HT (avec remise) : ';
 
                 if($optionsPrices) {
-                    $productsMessage[$indexMessage] .= 'Prix de base : ' . $cartData_[$index]['basic_selling_price'] . "€ HT\n";
+                    $productsMessage[$indexMessage] .= 'Prix de base : ' . ECommerceCommon::formatPrice($cartByID[0]['basic_selling_price']) . "€ HT\n";
                     foreach ($optionsPrices[1] as $key => $v) {
                         $productsMessage[$indexMessage] .= $v . " (+".array_values($optionsPrices[0])[0][$key]."€ HT)\n";
                     }
@@ -349,9 +350,9 @@ class AjaxController extends CubistFrontController
                     $labelPriceDiscount = 'Prix unitaire HT (avec options et remise) : ';
                 }
 
-                $productsMessage[$indexMessage] .= isset($price) && $cartData_[$index]['basic_selling_price'] ? $labelPrice . $price . "€ \n" : "";
+                $productsMessage[$indexMessage] .= isset($price) && $cartByID[0]['basic_selling_price'] ? $labelPrice . ECommerceCommon::formatPrice($price) . "€ \n" : "";
                 if ($discount) {
-                    $productsMessage[$indexMessage] .= $labelPriceDiscount . $priceDiscount . "€ \n";
+                    $productsMessage[$indexMessage] .= $labelPriceDiscount . ECommerceCommon::formatPrice($priceDiscount) . "€ \n";
                 }
             }
             $productsMessage[$indexMessage] .= 'Qté : ' . $_data . "\n\n";
@@ -367,10 +368,10 @@ class AjaxController extends CubistFrontController
             $tva = ECommerceCommon::tva($totalHT);
             $totalTTC = ECommerceCommon::totalTTC($totalHT);
 
-            $productsMessage[$indexMessage] .= "Frais de ports : ".($totalHT < 1000 ? 20 : 0)."€\n";
-            $productsMessage[$indexMessage] .= "Total HT : $totalHT"."€\n";
-            $productsMessage[$indexMessage] .= "Montant TVA : $tva"."€\n";
-            $productsMessage[$indexMessage] .= "Total TTC : $totalTTC"."€\n";
+            $productsMessage[$indexMessage] .= "Frais de ports : ".($totalHT < 1000 ? '20,00' : 0)."€\n";
+            $productsMessage[$indexMessage] .= "Total HT :". ECommerceCommon::formatPrice($totalHT) ."€\n";
+            $productsMessage[$indexMessage] .= "Montant TVA :". ECommerceCommon::formatPrice($tva) ."€\n";
+            $productsMessage[$indexMessage] .= "Total TTC :". ECommerceCommon::formatPrice($totalTTC) ."€\n";
             $productsMessage[$indexMessage] .= "\n----\n\n";
 
             $productsMessage[$indexMessage] .= "Adresse de facturation : \n";
index 83e080f684937eb4f0661006f8379039755eb6cc..fbf94592af85a17c93fefcc854256859a1cbb192 100644 (file)
@@ -120,14 +120,13 @@ const app = new Vue({
         });
 
         this.ref = this.$refs.refProduct?.dataset.ref
-        this.price = parseFloat(this.$refs.optprice ?.dataset.default).toFixed(2)
+        this.price = this.$refs.optprice ?.dataset.default
         this.statusText = this.$refs.statusConfig ?.dataset.incomplete
         this.discount = this.$refs.discount ?.dataset.value
         this.validateAction = this.$refs.forgotpwd ?.dataset.status //specific code for the forgot password confirmation
 
         let option = this.$refs.optionsExist?.dataset.val;
         this.statusConfig = !option && this.price ? true : false
-        console.log("option",option)
     },
 
     watch: {
@@ -171,8 +170,8 @@ const app = new Vue({
 
         priceDiscount() {
             let discount = this.discount ?? 0
-            let newValue = (this.price * discount) / 100
-            return (this.price - newValue).toFixed(2)
+            let newValue = (parseFloat(this.price) * discount) / 100
+            return parseFloat(this.price) - newValue
         }
     },
 
@@ -523,7 +522,7 @@ const app = new Vue({
 
             this.ref = this.$refs.refProduct.dataset.ref+'|'+placeholder
             this.price = total + parseFloat(this.$refs.optprice.dataset.default)
-            this.price = parseFloat(this.price).toFixed(2)
+            this.price = parseFloat(this.price)
         },
         /**
          *
@@ -632,7 +631,16 @@ const app = new Vue({
                 .catch(function (error) {
                     }
                 )
-        }
+        },
+        formatPrice(price) {
+            let price_ = price.toString()
+            let baseFormat = price_.replace(",","")
+            let toFloat = parseFloat(baseFormat);
+            let withDecimal = toFloat.toFixed(2);
+            let withoutComma = withDecimal.replace(",","");
+            let pointToComma = withoutComma.replace(".",",");
+            return pointToComma.replace(" ","");
+        },
     },
     /**
      * The following block of code is used for to close "modal confirm update/register"
index 3a7cf26adcbb59656f388366453dc3ea1aca18a4..17d4825efaec630c5b9a0351863b9ee2305748ff 100644 (file)
                 <number-input v-model="item.quantity" :min="1" inline center controls></number-input>
             </div>
             <div v-if="(!isNaN(parseFloat(item.price)) && parseFloat(item.price) > 0) && parseInt(item.price) > 0" :class="{ 'line-through' : item.discount > 0 }">
-                <span class="text-navy">{{ Number.parseFloat(price).toFixed(2) }}<span>€ HT</span></span>
+                <span class="text-navy">{{ formatPrice(price) }}<span>€ HT</span></span>
             </div>
             <div v-if="(item.discount > 0 && parseFloat(item.price) > 0) && parseInt(item.price) > 0">
-                <span class="text-navy">{{ Number.parseFloat(priceDiscount).toFixed(2) }}€ HT</span>
+                <span class="text-navy">{{ formatPrice(priceDiscount) }}€ HT</span>
             </div>
             <a href="#" class="cart-delete-item text-red" @click.prevent="deleteItem">
                 Supprimer
@@ -52,7 +52,6 @@
             eventBus.$emit('send-id', {
                 id: this.item.id
             });
-            console.log("item price",this.item.price)
         },
 
         watch: {
@@ -74,8 +73,7 @@
 
         computed: {
             price() {
-                console.log("priiiiice",this.item.price)
-                return (this.item.price * this.item.quantity)
+                return this.item.price * this.item.quantity
             },
 
             priceDiscount() {
         methods: {
             deleteItem() {
                 eventBus.$emit('delete-item', {id: this.item.id, ref: this.item.ref} );
-            }
+            },
+            formatPrice(price) {
+                let price_ = price.toString()
+
+                let baseFormat = price_.replace(",","")
+                let toFloat = parseFloat(baseFormat);
+                let withDecimal = toFloat.toFixed(2);
+                let withoutComma = withDecimal.replace(",","");
+                let pointToComma = withoutComma.replace(".",",");
+                return pointToComma.replace(" ","");
+            },
         }
     }
 </script>
index ca150d0500569371596823c34b1e36c5f6fc15a1..8669b18b5e2e375006b25799543f7c68e11a7d89 100644 (file)
@@ -45,7 +45,7 @@
                                         </span>
                                     </p>
                                     <p class="no-m">{{ __('Votre prix') }} : <span class="text-navy">{{
-                                        \App\Models\ECommerceCommon::formatPrice(\App\Models\ECommerceCommon::priceWithDiscount($product['basic_selling_price'], $product['discount']), 2) }} € HT</span>
+                                        \App\Models\ECommerceCommon::formatPrice(\App\Models\ECommerceCommon::priceWithDiscount($product['price'], $product['discount'])) }} € HT</span>
                                     </p>
                                 @endif
                             @else
@@ -99,7 +99,7 @@
                 </div>
                 @if($item['total'])
                     <div class="text-right pb-6">
-                        <p class="no-m">{{ __('Frais de port HT') }} : {{ \App\Models\ECommerceCommon::formatPrice($prices < 1000 ? 20 : 0) }}€</p>
+                        <p class="no-m">{{ __('Frais de port HT') }} : {{ $prices < 1000 ? "20,00" : 0 }}€</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>
index c1dc1bf7d4999541bc77b493278d43b0b394fb50..0855e471bca6d454e54e59070cecaf282913ffab 100644 (file)
@@ -84,7 +84,7 @@
             <div class="<?php echo $page !== 'order' ?: 'flex justify-between' ?>">
                 @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">{{ __('Frais de port HT') }} : {{ $prices < 1000 ? "20,00" : 0 }}€</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>
index 35c2d70d94694e479be30d8dec8cab00b9a61493..094efc9588761f05258fd8c1911680cadf43719a 100644 (file)
 
                     <div class="bg-grey-100 p-1v pt-0" v-cloak v-if="cartItemCount === cartItemHasPriceCount">
                         <div class="cart-shipping-fees text-navy">
-                            {{ __('Frais de ports') }} : <span v-cloak>@{{ total < 1000 ? '20€' : '0€' }} HT</span>
+                            {{ __('Frais de ports') }} : <span v-cloak>@{{ total < 1000 ? '20,00€' : '0€' }} HT</span>
                         </div>
                         <div class="cart-total">
-                            <p class="text-2xl text-navy">{{ __('Total HT') }} : <span v-cloak>@{{ total }}</span>€</p>
-                            <p class="text-2xl text-navy">{{ __('Montant TVA') }} : <span v-cloak>@{{ tva }}</span>€</p>
-                            <p class="text-2xl text-navy">{{ __('Total TTC') }} : <span v-cloak>@{{ totalTTC }}</span>€</p>
+                            <p class="text-2xl text-navy">{{ __('Total HT') }} : <span v-cloak>@{{ formatPrice(total) }}</span>€</p>
+                            <p class="text-2xl text-navy">{{ __('Montant TVA') }} : <span v-cloak>@{{ formatPrice(tva) }}</span>€</p>
+                            <p class="text-2xl text-navy">{{ __('Total TTC') }} : <span v-cloak>@{{ formatPrice(totalTTC) }}</span>€</p>
                         </div>
                     </div>
                     <button class="cart-valid-command btn btn-custom xs:w-full" data-id="" v-cloak v-if="cartItemCount === cartItemHasPriceCount" @click="order({{$pageId}})">
index da21190a831fe6792e4f24c13b44965a4a700b91..9e6f437ee3b01a319244d2171ed7c496bb36a339 100644 (file)
                                     @if($discount)
                                         <div>
                                             {{ __('Prix catalogue') }} :
-                                            <span class="line-through" ref="optprice" v-cloak data-default="{{ $product->basic_selling_price }}">@{{ price }}</span>{{ "€ ".__('HT') }}
+                                            <span class="line-through" ref="optprice" v-cloak data-default="{{ $product->basic_selling_price }}">
+                                                @{{ formatPrice(price) }}
+                                            </span>
+                                            {{ "€ ".__('HT') }}
                                         </div>
                                         <div>
                                             {{ __('Votre prix') }} :
                                             <span ref="discount" data-value="{{ $discount }}"></span>
-                                            <span v-cloak data-default="{{ $product->basic_selling_price }}">@{{ priceDiscount }}</span>{{ "€ ".__('HT') }}
+                                            <span v-cloak data-default="{{ $product->basic_selling_price }}">
+                                                @{{ formatPrice(priceDiscount) }}
+                                            </span>
+                                            {{ "€ ".__('HT') }}
                                         </div>
                                     @else
                                         {{ __('Prix unitaire') }} :
-                                        <span ref="optprice" v-cloak data-default="{{ $product->basic_selling_price }}">@{{ price }}</span>{{ "€ ".__('HT') }}
+                                        <span ref="optprice" v-cloak data-default="{{ \App\Models\ECommerceCommon::formatPrice($product->basic_selling_price) }}">
+                                            @{{ price }}
+                                        </span>{{ "€ ".__('HT') }}
                                     @endif
                                 </div>
                                 @if($options)
index 813e38d0f9ef329c3c2ec0b064e8c0f3d08c3f28..26cea4338e69d6b6b64e6aae1fc74b87411525cf 100644 (file)
@@ -65,7 +65,7 @@
                         {{ __("Vous n'avez encore rien sélectionné") }}
                     </div>
                     <div class="shipping-coast" v-if="cartItemCount > 0 && cartItemCount === cartItemHasPriceCount">
-                        Frais de ports : @{{ total - 20 < 1000 ? 20 : 0 }} € HT
+                        Frais de ports : @{{ total - 20 < 1000 ? '20,00' : 0 }} € HT
                     </div>
                 </div>
                 <div class="cart-header-popout-footer" v-cloak v-if="cartItemCount > 0 && cartItemCount !== cartItemHasPriceCount">
@@ -80,7 +80,7 @@
                 </div>
                 <div class="cart-header-popout-footer" v-cloak v-else-if="cartItemCount > 0 && cartItemCount === cartItemHasPriceCount">
                     <div class="cart-total text-navy text-center mb-5 text-2xl">
-                        {{__('Total'). ':' }} @{{ total }}€ HT
+                        {{__('Total'). ':' }} @{{ formatPrice(total) }}€ HT
                     </div>
                     <link-button class="block text-center" :href="$nav->getHrefByName('order')">
                         {{ __('Valider la commande') }}
index 45a0f214afdac4bf948a4ac1a4601ddca942e58f..3190432de29149d496f419593c6359a11844c55b 100644 (file)
                     @if($product->basic_selling_price && $product->json)
                         @php($options = true)
                         <p class="no-m text-sm mt-5 label">{{ __('Produit configurable') }}</p>
-                        <p class="price">{{ __('A partir de :').' '. $price }}€ HT</p>
+                        <p class="price">{{ __('A partir de :').' '. \App\Models\ECommerceCommon::formatPrice($price) }}€ HT</p>
                     @elseif($product->basic_selling_price && !$product->json)
                         <p class="no-m line-through text-sm mt-5 label">{{ __('Prix catalogue :').' '.$product->basic_selling_price }}€ HT</p>
-                        <p class="price">{{ __('Votre prix :').' '. $price }}€ HT</p>
+                        <p class="price">{{ __('Votre prix :').' '. \App\Models\ECommerceCommon::formatPrice($price) }}€ HT</p>
                     @endif
                 </div>
             @endif