From c3e005e235c5d74db274ec6a4dae3d8ca93131d1 Mon Sep 17 00:00:00 2001 From: soufiane Date: Thu, 31 Aug 2023 16:42:30 +0200 Subject: [PATCH] wait #6230 @5:00 --- app/Http/Controllers/AjaxController.php | 55 ++++++++++++------- app/Models/ECommerceCommon.php | 2 +- app/Models/Product.php | 5 +- resources/js/app.js | 1 + resources/js/components/CartItem.vue | 11 ++-- resources/views/components/cart-add.blade.php | 53 ++++++++---------- .../views/partials/product-link.blade.php | 22 ++++---- 7 files changed, 83 insertions(+), 66 deletions(-) diff --git a/app/Http/Controllers/AjaxController.php b/app/Http/Controllers/AjaxController.php index 0877576..2d35934 100644 --- a/app/Http/Controllers/AjaxController.php +++ b/app/Http/Controllers/AjaxController.php @@ -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) diff --git a/app/Models/ECommerceCommon.php b/app/Models/ECommerceCommon.php index 7d93faa..4e1a86b 100644 --- a/app/Models/ECommerceCommon.php +++ b/app/Models/ECommerceCommon.php @@ -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) { diff --git a/app/Models/Product.php b/app/Models/Product.php index d1a5f52..b05f1b1 100644 --- a/app/Models/Product.php +++ b/app/Models/Product.php @@ -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; diff --git a/resources/js/app.js b/resources/js/app.js index 46cd964..5fe35ec 100644 --- a/resources/js/app.js +++ b/resources/js/app.js @@ -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; } diff --git a/resources/js/components/CartItem.vue b/resources/js/components/CartItem.vue index f53ef36..3a7cf26 100644 --- a/resources/js/components/CartItem.vue +++ b/resources/js/components/CartItem.vue @@ -15,10 +15,10 @@ Quantité -
+
{{ Number.parseFloat(price).toFixed(2) }}€ HT
-
+
{{ Number.parseFloat(priceDiscount).toFixed(2) }}€ HT
@@ -52,6 +52,7 @@ eventBus.$emit('send-id', { id: this.item.id }); + console.log("item price",this.item.price) }, watch: { @@ -67,14 +68,14 @@ 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() { diff --git a/resources/views/components/cart-add.blade.php b/resources/views/components/cart-add.blade.php index 4dd29f2..2ce34a2 100644 --- a/resources/views/components/cart-add.blade.php +++ b/resources/views/components/cart-add.blade.php @@ -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) - -@else - @if(isset($template) && $template === "product-detail") - - @endif @endif diff --git a/resources/views/partials/product-link.blade.php b/resources/views/partials/product-link.blade.php index 2fcd9c3..45a0f21 100644 --- a/resources/views/partials/product-link.blade.php +++ b/resources/views/partials/product-link.blade.php @@ -32,16 +32,18 @@ {{$product->get('name')}}
-
- @if($product->basic_selling_price && $product->json) - @php($options = true) -

{{ __('Produit configurable') }}

-

{{ __('A partir de :').' '. $price }}€ HT

- @elseif($product->basic_selling_price && !$product->json) -

{{ __('Prix catalogue :').' '.$product->basic_selling_price }}€ HT

-

{{ __('Votre prix :').' '. $price }}€ HT

- @endif -
+ @if(\App\Models\Client::getClientConnected()) +
+ @if($product->basic_selling_price && $product->json) + @php($options = true) +

{{ __('Produit configurable') }}

+

{{ __('A partir de :').' '. $price }}€ HT

+ @elseif($product->basic_selling_price && !$product->json) +

{{ __('Prix catalogue :').' '.$product->basic_selling_price }}€ HT

+

{{ __('Votre prix :').' '. $price }}€ HT

+ @endif +
+ @endif @if(config('features.quote')) -- 2.39.5