]> _ Git - pmi.git/commitdiff
wip #5858 @5:00
authorsoufiane <soufiane@cubedesigners.com>
Wed, 19 Apr 2023 15:06:36 +0000 (17:06 +0200)
committersoufiane <soufiane@cubedesigners.com>
Wed, 19 Apr 2023 15:06:36 +0000 (17:06 +0200)
app/Http/Controllers/AjaxController.php
resources/js/app.js
resources/views/components/modal-confirm.blade.php
resources/views/pages/cart.blade.php
resources/views/pages/paniers_enregistres.blade.php

index 9c712493558c089d3c8bfab4c7dd8d24072de60e..5f264f5da97716139e3de049ba8efb50f1d32229 100644 (file)
@@ -611,15 +611,20 @@ class AjaxController extends CubistFrontController
             }) : 0;
 
             $basicPriceByProductId = $data['products'][$keyRefs]["basic_selling_price"];
-            $price = floatval(($basicPriceByProductId + $totalOptionsPrice) * $quantity);
-            $data['products'][$keyRefs]["price"] = $total[] = $price;
+            $price = floatval($basicPriceByProductId + $totalOptionsPrice);
+            $total[] = floatval($price * $quantity);
+            $data['products'][$keyRefs]["price"] = $price;
         }
 
+        $checkUnavailableEcommerceProduct = array_filter($data['products'], function($n) {
+            return !$n['price'];
+        });
+
         $ht = array_reduce($total, function($carry, $item) { return $carry + $item; });
-        $ht += ($total > 1000) ? 20 : 0;
+        $ht += ($ht > 1000) ? 20 : 0;
         $tva = $ht * 0.2;
         $ttc = $ht + $tva;
-        $data['total'] = $ttc;
+        $data['total'] = !$checkUnavailableEcommerceProduct ? $ttc : null;
 
         //
         $data['addresses'] = json_encode($data['addresses']);
@@ -633,7 +638,8 @@ class AjaxController extends CubistFrontController
             $id = $panier->getOriginal('id');
             $request->session()->put('last_selection', $id);
         } else {
-            Panier::where('id', $lastCartRefs)->update($data);
+
+            Panier::where('id', $lastCartId)->update($data);
         }
 
         return __('Le panier a été enregistré avec succès !');
@@ -666,7 +672,28 @@ class AjaxController extends CubistFrontController
     }
 
     public function savedCartToCurrent(Request $request) {
+        $request->validate([
+            'id' => 'required|numeric'
+        ]);
+
+        $cartId = $request->input('id');
 
-        //$this->cart()
+        $cart = Panier::find($cartId)->toArray();
+
+        $clientIdInRequest = intval($cart['user_id']);
+        $clientId = Client::getClientConnected()->id;
+
+        if($clientIdInRequest === $clientId) {
+            $cartData = json_decode($cart['products'],true);
+
+            // Clear cart session
+            $request->session()->forget('cart_items');
+
+            // Save back to the session
+            $request->session()->put('cart_items', $cartData);
+            $request->session()->put('last_selection', intval($cartId));
+            return "success";
+        }
+        return false;
     }
 }
index 1c18c89952638775ccf4c87e85c9151fddcc0a61..2dd6c855377be71758ee51a6a45b85da4cc3a658 100644 (file)
@@ -69,7 +69,7 @@ const app = new Vue({
         emailExist: false,
         validateEmail: false,
         address_choice: true,
-        validateForm: false,
+        validateAction: false,
         tab: 'infos',
         addresses: [{}],
         user: '',
@@ -82,7 +82,8 @@ const app = new Vue({
         statusConfig: false,
         statusText: '',
         //
-        nameSaved: {}
+        nameSaved: {},
+        confirmMessageCart: ''
     },
 
     beforeMount() {
@@ -327,7 +328,7 @@ const app = new Vue({
             axios.post('/ajax/signup', data)
                 .then(function (response) {
 
-                    root.validateForm = true
+                    root.validateAction = true
 
                     // Reset form
                     root.email_signin = ''
@@ -403,7 +404,7 @@ const app = new Vue({
             axios.post('/ajax/update', data)
                 .then(function (response) {
                     root.removeErrorsForm()
-                    root.validateForm = true
+                    root.validateAction = true
                     root.form[id] = response.data
                 })
                 .catch(function (error) {
@@ -420,7 +421,7 @@ const app = new Vue({
             axios.post('/ajax/updateAddress', data)
                 .then(function (response) {
                     root.removeErrorsForm()
-                    root.validateForm = true
+                    root.validateAction = true
                 })
                 .catch(function (error) {
                     root.errorHandling(error, root, formId)
@@ -488,7 +489,8 @@ const app = new Vue({
 
             axios.post('/ajax/storecart', data)
                 .then(function (response) {
-                    console.log(response)
+                    root.validateAction = true
+                    root.confirmMessageCart = response.data;
                 })
                 .catch(function (error) {
                     console.log(error)
@@ -529,10 +531,17 @@ const app = new Vue({
                 .catch(function (error) {
                 })
         },
-        savedCartToCurrent() {
-            const data = {
+        savedCartToCurrent(event) {
+            const   id = event.target.dataset.id,
+                    homeUrl = window.location.origin;
 
-            }
+            axios.post('/ajax/savedCartToCurrent', {id: id})
+                .then(function (response) {
+                    //root.animateDelete(el)
+                    window.location.replace(homeUrl+'/ma-selection')
+                })
+                .catch(function (error) {
+                })
         }
     },
     /**
@@ -550,7 +559,7 @@ const app = new Vue({
                 const vm = vnode.context;
                 Window.event = (e) => {
                     if (!el.contains(e.target) || e.key === "Escape") {
-                        vm.validateForm = false
+                        vm.validateAction = false
                     }
                 }
                 document.body.addEventListener('click', Window.event)
index 8517ca5ad483128a98e84dde02c89767d7190b24..d7c8257982126ac4c6cf970beca169c1d399da6c 100644 (file)
@@ -1,6 +1,6 @@
-<div class="modal-confirm fixed top-0 left-0 flex items-center" v-cloak v-if="validateForm">
+<div class="modal-confirm fixed top-0 left-0 flex items-center" v-cloak v-if="validateAction">
     <div class="modal-confirm-text relative text-2xl bg-white p-24 text-center mx-auto" v-close-outside>
-        <button class="modal-confirm-close absolute" @click.prevent="validateForm = false">
+        <button class="modal-confirm-close absolute" @click.prevent="validateAction = false">
             @svg('icon-close-thin', 'w-4')
         </button>
         {{ $slot }}
index 1aba191f0502aa552c2df3d05b4f63de11ddc641..8f58537e1b34cfccc0c02311551e77818a682766 100644 (file)
         </div>
 
     </content>
-
+    <modal-confirm>
+        <p>@{{ confirmMessageCart }}</p>
+    </modal-confirm>
 @endsection
index 176264172a649d5051d2c9b44b596a3f5f64aaa2..597af0e612c7dfe5ceb18a82be6525105d1a5d1d 100644 (file)
@@ -9,7 +9,7 @@
                 <div id="cart-saved-{{ $cart['id'] }}" class="cartsave bg-grey-200 pr-2v pl-2v">
                     <div class="cartsave-name">
                         <div>
-                            <textarea id="cart-name-{{ $cart['id'] }}" class="readonly" value="{{ $cart['name'] }}" readonly />
+                            <input id="cart-name-{{ $cart['id'] }}" class="readonly" value="{{ $cart['name'] }}" readonly />
                         </div>
                         <a href="#" data-input="{{ $cart['id'] }}" class="inline-block animated-underline" data-defaulttext="{{ __('Editer le nom du panier') }}" data-edittext="{{ __('Sauvegarder le nom du panier') }}" @click.prevent.self="toggleName">
                             {{ __('Editer le nom du panier') }}
@@ -63,7 +63,9 @@
                             </button>
 
                             <div class="flex items-center">
-                                <a href="" class="animated-underline mr-10 xs:mr-0">{{ __('Modifier ce panier') }}</a>
+                                <a href="#" data-id="{{ $cart['id'] }}" class="animated-underline mr-10 xs:mr-0" @click.self.prevent="savedCartToCurrent">
+                                    {{ __('Modifier ce panier') }}
+                                </a>
                                 @isset($cart['total'])
                                     <a href="" class="btn">{{ __('Passer commande') }}</a>
                                 @else