]> _ Git - pmi.git/commitdiff
wait #6230 @5:00
authorsoufiane <soufiane@cubedesigners.com>
Thu, 31 Aug 2023 14:42:30 +0000 (16:42 +0200)
committersoufiane <soufiane@cubedesigners.com>
Thu, 31 Aug 2023 14:42:30 +0000 (16:42 +0200)
app/Http/Controllers/AjaxController.php
app/Models/ECommerceCommon.php
app/Models/Product.php
resources/js/app.js
resources/js/components/CartItem.vue
resources/views/components/cart-add.blade.php
resources/views/partials/product-link.blade.php

index 0877576ae9ac942a8c660fd5f560fdaa30bf64c0..2d359346df2d7f2561dd7257e5da1317688eb40c 100644 (file)
@@ -112,8 +112,10 @@ class AjaxController extends CubistFrontController
     {
         $contents = [];
 
-        $validatedData['tva'] = Client::getClientConnected()->vat;
-        $validatedData['siren'] = Client::getClientConnected()->siren;
+        if(Client::getClientConnected()) {
+            $validatedData['tva'] = Client::getClientConnected()->vat;
+            $validatedData['siren'] = Client::getClientConnected()->siren;
+        }
 
         foreach (self::$_labels as $key => $label) {
             if (isset($validatedData[$key])) {
@@ -188,6 +190,10 @@ class AjaxController extends CubistFrontController
         $ref = $request->input('ref') ?? '';
         $price = $request->input('price') ?? '';
 
+        if(!Client::getClientConnected()) {
+            $price = '';
+        }
+
         // Get existing session or an empty array
         $cart_items = $request->session()->get('cart_items', []);
 
@@ -250,7 +256,10 @@ class AjaxController extends CubistFrontController
                     $needs_update = true;
                 }
                 $cart_items[$currentIndex]['quantity'] = $quantity;
-                //$cart_items[$currentIndex]['price'] = $price;
+                if(!Client::getClientConnected()) {
+                    $cart_items[$currentIndex]['price'] = 0;
+                    $cart_items[$currentIndex]['basic_selling_price'] = 0;
+                }
                 break;
 
             case 'delete':
@@ -301,6 +310,7 @@ class AjaxController extends CubistFrontController
             $basicSellingPrice = $products[$id]['basic_selling_price'];
             $categoryProduct = $products[$id]['category'];
             $discount = intval(Client::getDiscount($categoryProduct, Client::getCategory()));
+            $price = 0;
 
             if($basicSellingPrice) {
                 $price = $basicSellingPrice;
@@ -313,32 +323,36 @@ class AjaxController extends CubistFrontController
                 $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' => $cartData_[$index]['ref'],
+                'reference' => (empty($pr_cart_data['ref']) ? $pr_cart_data['reference'] : $pr_cart_data['ref']),
                 'name' => $products[$id]['name'],
                 'quantity' => $_data,
-                'price' => isset($price) ? ECommerceCommon::priceWithDiscount($price, $discount)."€" : 0
+                'price' => isset($price) && intval($price) > 0 && Client::getClientConnected() ? ECommerceCommon::priceWithDiscount($price, $discount)."€" : 0
             ];
 
-            $productsMessage[] = 'Référence : ' . $cartData_[$index]['ref'] . "\n";
+            $productsMessage[] = 'Référence : ' . (empty($cartData_[$index]['ref']) ? $cartData_[$index]['reference'] : $cartData_[$index]['ref']) . "\n";
             $productsMessage[$indexMessage] .= url("/{$products[$id]['slug']}")."\n";
 
-            $labelPrice = 'Prix unitaire HT : ';
-            $labelPriceDiscount = 'Prix unitaire HT (avec remise) : ';
+            if(Client::getClientConnected()) {
+                $labelPrice = 'Prix unitaire HT : ';
+                $labelPriceDiscount = 'Prix unitaire HT (avec remise) : ';
 
-            if($optionsPrices) {
-                $productsMessage[$indexMessage] .= 'Prix de base : ' . $cartData_[$index]['basic_selling_price'] . "€ HT\n";
-                foreach ($optionsPrices[1] as $key => $v) {
-                    $productsMessage[$indexMessage] .= $v . " (+".array_values($optionsPrices[0])[0][$key]."€ HT)\n";
+                if($optionsPrices) {
+                    $productsMessage[$indexMessage] .= 'Prix de base : ' . $cartData_[$index]['basic_selling_price'] . "€ HT\n";
+                    foreach ($optionsPrices[1] as $key => $v) {
+                        $productsMessage[$indexMessage] .= $v . " (+".array_values($optionsPrices[0])[0][$key]."€ HT)\n";
+                    }
+                    $labelPrice = 'Prix unitaire HT (avec options) : ';
+                    $labelPriceDiscount = 'Prix unitaire HT (avec options et remise) : ';
                 }
-                $labelPrice = 'Prix unitaire HT (avec options) : ';
-                $labelPriceDiscount = 'Prix unitaire HT (avec options et remise) : ';
-            }
 
-            $productsMessage[$indexMessage] .= isset($price) ? $labelPrice.$price . "€ \n" : "";
-            if($discount) {
-                $productsMessage[$indexMessage] .= $labelPriceDiscount.$priceDiscount. "€ \n";
+                $productsMessage[$indexMessage] .= isset($price) && $cartData_[$index]['basic_selling_price'] ? $labelPrice . $price . "€ \n" : "";
+                if ($discount) {
+                    $productsMessage[$indexMessage] .= $labelPriceDiscount . $priceDiscount . "€ \n";
+                }
             }
             $productsMessage[$indexMessage] .= 'Qté : ' . $_data . "\n\n";
             $productsMessage[$indexMessage] .= "----\n\n";
@@ -384,14 +398,15 @@ class AjaxController extends CubistFrontController
             $quote->save();
 
             $linkTo = 'Voir la demande en ligne : ' . url('/admin/quotes/' . $quote->id . '/edit');
+            $subj = null;
         }else {
             $linkTo = 'Voir la commande en ligne : ' . url('/admin/order/' . $save->id . "/edit \n");
+            $subj = "Nouvelle commande";
         }
 
         $validatedData['id'] = $save ? $save->id : $quote->id;
 
-
-        $this->_sendMail($validatedData, $page, [implode("\r\n", $productsMessage), '', $linkTo], "Nouvelle commande");
+        $this->_sendMail($validatedData, $page, [implode("\r\n", $productsMessage), '', $linkTo], $subj);
     }
 
     public function search(Request $request)
index 7d93faa9148a132aa932ce85c9950ba35f0f171b..4e1a86b816d4ecd5b966a677d357a4a17f2d3ed4 100644 (file)
@@ -102,7 +102,7 @@ class ECommerceCommon extends CubistMagicAbstractModel
 
             $data['products'][$keyRefs]['discount'] = $discount;
             $data['products'][$keyRefs]["basic_selling_price"] = $basicSellingPrice;
-            $data['products'][$keyRefs]["price"] = $price;
+            $data['products'][$keyRefs]["price"] = Client::getClientConnected() ? $price : 0;
         }
 
         $unavailableEcommerceProduct = array_filter($data['products'], function($n) {
index d1a5f522f3781298338152d0eff18f18bbc4b9f4..b05f1b1ed86debb8f7d7a5d42b48cf11b9c9704e 100644 (file)
@@ -476,7 +476,6 @@ class Product extends CubistMagicPageModel
     public static function getCartData($cart_items = [])
     {
         if (!self::$_cart_data && isset($cart_items)) {
-
             if(sizeof($cart_items) < 1) {
                 $cart_items = session('cart_items', []);
                 self::$_cart_data = [];
@@ -494,6 +493,10 @@ class Product extends CubistMagicPageModel
                     $id = $values["id"];
                     $getCartItem = array_values(array_filter($productsSellingBasicPrice, function($n) use($id) { return $n['id'] === $id; }));
                     $values["basic_selling_price"] = floatval($getCartItem[0]["basic_selling_price"]) ?? 0;
+                    if(!Client::getClientConnected()) {
+                        $values["basic_selling_price"] = 0;
+                        $values["price"] = 0;
+                    }
                 }
 
                 self::$_cart_data = $cart_items;
index 46cd964c726f76dc4223634547ceab42e0fe79f2..5fe35ec5757e3df608c15e510e879b5ace52a0b5 100644 (file)
@@ -182,6 +182,7 @@ const app = new Vue({
             axios.post('/ajax/cart', data)
                 .then(function (response) {
                     if (response.data.needs_update) {
+                        console.log("response",response.data.cart_data)
                         root.items = response.data.cart_data;
                     }
 
index f53ef364a729a319ea7199e7c33dc75e3475987e..3a7cf26adcbb59656f388366453dc3ea1aca18a4 100644 (file)
                 <span class="mr-2">Quantité</span>
                 <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" :class="{ 'line-through' : item.discount > 0 }">
+            <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>
             </div>
-            <div v-if="item.discount > 0 && parseFloat(item.price) > 0">
+            <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>
             </div>
             <a href="#" class="cart-delete-item text-red" @click.prevent="deleteItem">
@@ -52,6 +52,7 @@
             eventBus.$emit('send-id', {
                 id: this.item.id
             });
+            console.log("item price",this.item.price)
         },
 
         watch: {
                     ref: this.item.ref,
                     price: this.price,
                     quantity: newValue,
-                }
-                );
+                });
             },
         },
 
         computed: {
             price() {
-                return this.item.price * this.item.quantity
+                console.log("priiiiice",this.item.price)
+                return (this.item.price * this.item.quantity)
             },
 
             priceDiscount() {
index 4dd29f28981f7ca3639748cf57ad3125c70c6b4b..2ce34a2e8770369d72968f97c7c40e6ffee41715 100644 (file)
@@ -1,40 +1,35 @@
 @php
     if(isset($price)) {
         $btnText = __('Ajouter au panier');
-        if(isset($options) && $options)
+        if(isset($options) && $options && \App\Models\Client::getClientConnected())
             $btnText = __('Configurer le produit');
     } else {
         $btnText = __('Ajouter à ma sélection');
     }
+
+    if(!\App\Models\Client::getClientConnected()) {
+        $price = "";
+        $options = "";
+    }
 @endphp
 
-@if(!\App\Models\Client::getClientConnected() && $hasprice)
-    <button class="btn pointer-events-none bg-grey-disabled">
-        <span class="btn-text relative">
-            <span class="add">
-                {{ $btnText }}
-            </span>
-        </span>
+@if(isset($template) && $template === "product-detail")
+    <button data-ref="{{ $reference }}" data-product-id="{{ $id }}" class="btn cart-add" :class="{ 'pointer-events-none bg-grey-disabled' : (!isNaN(price) && !statusConfig) }">
+        @elseif(isset($template) && $template === "miniature" && $options)
+            <a href="{{ $link }}" class="btn text-center">
+                @else
+                    <button data-ref="{{ $reference }}" data-price="{{ $price }}" data-product-id="{{ $id }}" class="btn cart-add">
+                        @endif
+                        <span class="btn-text relative">
+                            <span class="add">
+                                {{ $btnText }}
+                            </span>
+                            <span class="added top-0 left-0 w-full h-full inline-flex items-center justify-center hidden" style="top:-2px;">
+                                @svg('tick', 'w-4 mr-3 inline left-0') <span>{{ __('Produit ajouté') }}</span>
+                            </span>
+                        </span>
+                    @if(isset($template) && $template === "miniature" && $options)
+            </a>
+        @else
     </button>
-@else
-    @if(isset($template) && $template === "product-detail")
-        <button data-ref="{{ $reference }}" data-product-id="{{ $id }}" class="btn cart-add" :class="{ 'pointer-events-none bg-grey-disabled' : (!isNaN(price) && !statusConfig) }">
-            @elseif(isset($template) && $template === "miniature" && $options)
-                <a href="{{ $link }}" class="btn text-center">
-                    @else
-                        <button data-ref="{{ $reference }}" data-price="{{ $price }}" data-product-id="{{ $id }}" class="btn cart-add">
-                            @endif
-                            <span class="btn-text relative">
-            <span class="add">
-                {{ $btnText }}
-            </span>
-            <span class="added top-0 left-0 w-full h-full inline-flex items-center justify-center hidden" style="top:-2px;">
-                @svg('tick', 'w-4 mr-3 inline left-0') <span>{{ __('Produit ajouté') }}</span>
-            </span>
-        </span>
-                        @if(isset($template) && $template === "miniature" && $options)
-                </a>
-            @else
-        </button>
-    @endif
 @endif
index 2fcd9c3583dbe685587177dda6c27aea8ba40776..45a0f214afdac4bf948a4ac1a4601ddca942e58f 100644 (file)
                     {{$product->get('name')}}
                 </div>
             </div>
-            <div class="product-price-info">
-                @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>
-                @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>
-                @endif
-            </div>
+            @if(\App\Models\Client::getClientConnected())
+                <div class="product-price-info">
+                    @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>
+                    @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>
+                    @endif
+                </div>
+            @endif
         </div>
         @if(config('features.quote'))
             <cart-add :id="$product->id" :reference="$product->reference" :link="$product->getEntity()->URL" :price="$price" :options="$options" :hasprice="$product->basic_selling_price" template="miniature"></cart-add>