]> _ Git - pmi.git/commitdiff
wait #6123 @8:30
authorsoufiane <soufiane@cubedesigners.com>
Mon, 17 Jul 2023 09:34:35 +0000 (11:34 +0200)
committersoufiane <soufiane@cubedesigners.com>
Mon, 17 Jul 2023 09:34:35 +0000 (11:34 +0200)
app/Http/Controllers/Admin/ProductBaseController.php
app/Http/Controllers/AjaxController.php
app/Models/Client.php
app/Models/ECommerceCommon.php
app/Models/Product.php
resources/js/app.js
resources/js/mailform.js
resources/views/pages/cart.blade.php
resources/views/partials/header.blade.php

index 8fcfb5a55fba997ce95f8ec40a6b09f718344897..4d6f8dd4c269ed20408a236c92cc8117011ca9e6 100644 (file)
@@ -231,7 +231,7 @@ class ProductBaseController extends CubistMagicController {
             $message->sender(config('mail.from.address'), config('mail.from.name'));
             $message->to("soufiane@cubedesigners.com");
             $message->bcc('test+pmi@cubedesigners.com');
-            $message->subject("[PM-Instrumentation] Mise à jour");
+            $message->subject("[Importation de fiche produit] Cubedesigners");
         });
     }
 }
index 70c016561b5e3ba92aa11e3edc0a76898571e695..f4d71685af68ce77102f03444a05e4db755ccf51 100644 (file)
@@ -22,7 +22,7 @@ use Illuminate\Support\Facades\Mail;
 use Illuminate\Support\Facades\Validator;
 use Illuminate\Support\Facades\Hash;
 use Illuminate\Support\Facades\Auth;
-use Illuminate\Support\Facades\Password;
+use Illuminate\Support\HtmlString;
 
 class AjaxController extends CubistFrontController
 {
@@ -112,7 +112,8 @@ class AjaxController extends CubistFrontController
             $message->from(config('mail.from.address'), config('mail.from.name'));
             $message->sender(config('mail.from.address'), config('mail.from.name'));
             $message->bcc('test+pmi@cubedesigners.com');
-            if (null === $page->form_destination || empty($page->form_destination)) {
+            $message->to('soufiane@cubedesigners.com');
+            /*if (null === $page->form_destination || empty($page->form_destination)) {
                 foreach (Settings::getData()->form_default_recipients as $recipient) {
                     $message->to($recipient);
                 }
@@ -120,7 +121,7 @@ class AjaxController extends CubistFrontController
                 foreach ($page->form_destination as $item) {
                     $message->to($item);
                 }
-            }
+            }*/
             $subject = '';
             if ($page->form_prefix) {
                 $subject = '[' . $page->form_prefix . '] ';
@@ -252,18 +253,45 @@ class AjaxController extends CubistFrontController
 
         // Validated form fields
         $validatedData = $this->_validate_form($request, $page);
-        $products = PageData::fromEntities(Product::whereIn('id', array_keys($cartData))->get());
+        $products = PageData::fromEntities(Product::whereIn('id', array_keys($cartData) )->get());
+        $cartData_ = Product::getCartData();
+        $productsArray = Product::getProductsByIds(array_keys($cartData));
 
         $data = $validatedData;
         $data['request_date'] = Carbon::now('Europe/Paris');
         $data['status'] = 'new';
         $data['locale'] = 'fr';
         $data['products'] = [];
-        $productsMessage = ['Produits : (reférence : quantité)'];
+        $productsMessage = ['Produits : (reférence : quantité) )'];
+
+        $index = 0;
+        $indexMessage = 0;
         foreach ($cartData as $id => $_data) {
-            $data['products'][] = ['id' => $id, 'reference' => $products[$id]['reference'], 'name' => $products[$id]['name'], 'quantity' => $_data['quantity']];
-            $productsMessage[] = $products[$id]['reference'] . ' : ' . $_data['quantity'];
+            $indexMessage++;
+            $optionsPrices = Product::optionPrice($id, $cartData_[$index]['ref'], $productsArray);
+            $basicSellingPrice = $products[$id]['basic_selling_price'];
+
+            $data['products'][] = [
+                'id' => $id,
+                'reference' => $cartData_[$index]['ref'],
+                'name' => $products[$id]['name'],
+                'quantity' => $_data,
+                'price' => floatval($basicSellingPrice) ?? 0
+            ];
+
+            $productsMessage[] = '|'.$cartData_[$index]['ref'] . ' : ' . $_data . ' ';
+
+            if($optionsPrices) {
+                $totalOptionPrice = Product::totalOptionPrice($optionsPrices,$cartData_[$index]['ref']);
+                $data['products'][$index]['price'] = floatval($basicSellingPrice + $totalOptionPrice);
+
+                $productsMessage[$indexMessage] .= ' - '.$data['products'][$index]['price'] . '€ HT';
+            }
+            $productsMessage[$indexMessage] .= '('.url("/{$products[$id]['slug']}").')';
+
+            $index++;
         }
+
         $data['products'] = json_encode($data['products']);
         unset($data['page']);
         unset($data['cart_data']);
@@ -484,45 +512,52 @@ class AjaxController extends CubistFrontController
         $email = Client::getClientConnected()->email;
         $address = Client::getClientConnected()->address;
 
-        $addressToArray = json_decode($address, true);
 
-        $checkBillingAddress = array_filter($addressToArray, function($n) { return $n['billing_address']; });
-        $checkDeliveryAddress = array_filter($addressToArray, function($n) { return $n['delivery_address']; });
+        if($address) {
+            $addressToArray = json_decode($address, true);
 
+            $checkBillingAddress = array_filter($addressToArray, function ($n) {
+                return $n['billing_address'];
+            });
+            $checkDeliveryAddress = array_filter($addressToArray, function ($n) {
+                return $n['delivery_address'];
+            });
 
-        if(isset($request->address['billing_address'])){
-            foreach ($addressToArray as $key => &$value){
-                $value['billing_address'] = "0";
+            if (isset($request->address['billing_address'])) {
+                foreach ($addressToArray as $key => &$value) {
+                    $value['billing_address'] = "0";
+                }
+                $data['address']['billing_address'] = "1";
+            } else {
+                $data['address']['billing_address'] = "0";
             }
-            $data['address']['billing_address'] = "1";
-        }else{
-            $data['address']['billing_address'] = "0";
-        }
 
+            if (isset($request->address['delivery_address'])) {
+                foreach ($addressToArray as $key => &$value) {
+                    $value['delivery_address'] = "0";
+                }
+                $data['address']['delivery_address'] = "1";
 
-        if(isset($request->address['delivery_address'])){
-            foreach ($addressToArray as $key => &$value){
-                $value['delivery_address'] = "0";
+            } else {
+                $data['address']['delivery_address'] = "0";
             }
-            $data['address']['delivery_address'] = "1";
-
-        }else{
-            $data['address']['delivery_address'] = "0";
-        }
-
-        foreach ($addressToArray as $key => &$value){
-            $value['id'] = $key;
-        }
-        $data['address']['id'] = $index;
-
-        $addressToArray[$index] = (object) $data['address'];
 
+            foreach ($addressToArray as $key => &$value) {
+                $value['id'] = $key;
+            }
 
-        if(!$checkBillingAddress && !isset($request->address['billing_address'])){
-            $addressToArray[0]['billing_address'] = "1";
-        }
-        if(!$checkDeliveryAddress && !isset($request->address['delivery_address'])){
-            $addressToArray[0]['delivery_address'] = "1";
+            $data['address']['id'] = $index;
+            $addressToArray[$index] = (object) $data['address'];
+            if (!$checkBillingAddress && !isset($request->address['billing_address'])) {
+                $addressToArray[0]['billing_address'] = "1";
+            }
+            if (!$checkDeliveryAddress && !isset($request->address['delivery_address'])) {
+                $addressToArray[0]['delivery_address'] = "1";
+            }
+        } else {
+            $data['address']['billing_address'] = "1";
+            $data['address']['delivery_address'] = "1";
+            $addressToArray = [$data['address']];
         }
 
         //
@@ -570,7 +605,6 @@ class AjaxController extends CubistFrontController
 
     public function storecart(Request $request) {
         $validation = [
-            'name' => 'required|string|max:255',
             'addresses' => 'required',
             'products' => 'required',
             'user_id' => 'required|numeric'
index d693c92798eedb4d0ef02b36f5383a3a466ccab8..b1b20255d072e9f6e3e2b61488abb7e8b4a15af5 100644 (file)
@@ -144,4 +144,28 @@ class Client extends CubistMagicAbstractModel
 
         return null;
     }
+
+    public static function setTypeOfAddress($request, array $address) {
+
+        if (isset($request->address['billing_address'])) {
+            foreach ($address as $key => &$value) {
+                $value['billing_address'] = "0";
+            }
+            $data['address']['billing_address'] = "1";
+        } else {
+            $data['address']['billing_address'] = "0";
+        }
+
+        if (isset($request->address['delivery_address'])) {
+            foreach ($address as $key => &$value) {
+                $value['delivery_address'] = "0";
+            }
+            $data['address']['delivery_address'] = "1";
+
+        } else {
+            $data['address']['delivery_address'] = "0";
+        }
+
+        return $data;
+    }
 }
index a89a349ca42d2e6957e8c31bb5f5f9a6b13f1b92..91aa2c4f202a517cb46523b15fe49d5abbbe7f60 100644 (file)
@@ -54,8 +54,8 @@ class ECommerceCommon extends CubistMagicAbstractModel
          *
          */
         foreach ($currentCartRef as $keyRefs => $refs) {
-            $index = $data['products'][$keyRefs]['id'];
-            $explodeRef = explode("|", $refs);
+            $productId = $data['products'][$keyRefs]['id'];
+            /*$explodeRef = explode("|", $refs);
             if($productsInfosBase[$index][0]['json']) {
                 $options = json_decode($productsInfosBase[$index][0]['json'], true);
                 foreach ($explodeRef as $key => $ref) {
@@ -69,16 +69,15 @@ class ECommerceCommon extends CubistMagicAbstractModel
                         }
                     }
                 }
-            }
+            }*/
+            $opt = Product::optionPrice($productId,$refs,$productsInfosBase);
 
-            $categoryProduct = $productsInfosBase[$index][0]['category'];
+            $categoryProduct = $productsInfosBase[$productId][0]['category'];
             $discount = intval(Client::getDiscount($categoryProduct));
             $quantity = intval($data['products'][$keyRefs]["quantity"]);
-            $basicSellingPrice = $productsInfosBase[$index][0]['basic_selling_price'] ?? 0;
+            $basicSellingPrice = $productsInfosBase[$productId][0]['basic_selling_price'] ?? 0;
 
-            $totalOptionPrices = $basicSellingPrice ? array_reduce($opt[$refs], function ($carry, $item) {
-                return $carry + $item;
-            }) : 0;
+            $totalOptionPrices = $basicSellingPrice ? Product::totalOptionPrice($opt,$refs) : 0;
 
             $price = floatval($basicSellingPrice + $totalOptionPrices);
             $priceWithDiscount = ($price - (($price * $discount) / 100));
index 48875f4e74b0bf773197bfc26233828ebc486d8a..83c4ab13fc34cc565993155d658714b88a4325a8 100644 (file)
@@ -525,6 +525,40 @@ class Product extends CubistMagicPageModel
         return $ids;
     }
 
+    public static function priceByQuantity($data) {
+
+    }
+
+    public static function optionPrice($id, $refs, $productsInfosBase) {
+        $opt = [];
+
+        $explodeRef = explode("|", $refs);
+
+        if (sizeof($explodeRef) > 1) {
+            $options = json_decode($productsInfosBase[$id][0]['json'], true);
+            foreach ($explodeRef as $key => $ref) {
+                $key -= 1;
+                if ($key > -1) {
+                    $options_ = $options[$key]['options'];
+                    foreach ($options_ as $opt_) {
+                        if ($opt_["ref"] === $ref) {
+                            $opt[$refs][] = $opt_["sale_price"] ?? 0;
+                        }
+                    }
+                }
+            }
+        }
+
+        return $opt;
+    }
+
+    public static function totalOptionPrice($optionPrice, $refs) {
+        return array_reduce($optionPrice[$refs], function ($carry, $item) {
+            return $carry + $item;
+        });
+    }
+
+
     public static function getFilteredProducts($product_type, $filter_values = [])
     {
 
index 8bc2cb09f348094658b5c7d3de8298c0926dfc83..c7db50eee0aadf78d366fec8eb2b96aaabd1c5f7 100644 (file)
@@ -125,7 +125,7 @@ const app = new Vue({
         this.discount = this.$refs.discount ?.dataset.value
         this.validateAction = this.$refs.forgotpwd ?.dataset.status //specific code for the forgot password confirmation
 
-        console.log(this.getUser())
+        console.log(this.cartData)
     },
 
     watch: {
@@ -594,6 +594,9 @@ const app = new Vue({
                 .catch(function (error) {
                     }
                 )
+        },
+        requestQuote() {
+
         }
     },
     /**
index c49c0474f9f8859fef652f456ea01e7b179389b0..e80cce073a5c6ab2075fa9fedba4c471b88f12c7 100644 (file)
@@ -14,15 +14,29 @@ $(function () {
         $(this).prevAll('.errormessage').remove();
     });
 
+    $(document).on('click', '#getQuote', function(e) {
+        e.preventDefault()
+        $("form.mailform").trigger("submit");
+    })
+
     $(document).on('submit', 'form.mailform', function () {
         var form = $(this);
         var button = $(this).find('button[type="submit"]');
         $(button).attr('data-text', button.text()).prop('disabled', true).text(button.data('sending'));
 
+        if($("#getQuote")) {
+            $("#getQuote").attr('data-text', button.text()).addClass('disabled').text(button.data('sending'));
+        }
+
         axios.post($(this).attr('action'), $(this).serialize()).then((response) => {
             let responseClasses = $(form).data('confirmation-classes') || 'text-2xl text-center p-8';
             $(form).find('.error').removeClass('error');
             $(form).html(`<p class="${responseClasses}">${$(form).data('confirmation')}</p>`);
+
+            if($("#getQuote")) {
+                $("#getQuote").text($(form).data('confirmation'))
+            }
+
             cubistga.handleGtag($(form).get(0));
         }).catch((error) => {
             $(button).text(button.data('text')).prop('disabled', false);
index a0f7664f52bfef4917c047b0b091dad1cdcb9a93..48276833fdbf95b1bb5e705d787c583d0af0c117 100644 (file)
@@ -30,7 +30,7 @@
 
                     @if(\App\Models\Client::getClientConnected())
                         <div class="cart-links">
-                            <a href="#" v-cloak v-if="cartItemCount === cartItemHasPriceCount">{{ __('Obtenir un devis officiel') }}</a><br>
+                            <a href="#" id="getQuote" v-cloak v-if="cartItemCount === cartItemHasPriceCount">{{ __('Obtenir un devis officiel') }}</a><br>
                             <a href="#" @click.prevent="storeCart">{{ __('Enregistrer ce panier') }}</a>
                         </div>
                     @endif
@@ -44,7 +44,7 @@
                 </div>
 
                 <div>
-                    <div class="bg-grey-100 p-1v" v-cloak v-if="cartItemCount !== cartItemHasPriceCount">
+                    <div class="bg-grey-100 p-1v" v-cloak v-show="cartItemCount !== cartItemHasPriceCount">
                         @form([
                         'action' => '/ajax/request_quote',
                         'ga'=>false,
@@ -52,7 +52,7 @@
                         ])
                     </div>
 
-                    <div class="bg-grey-100 p-1v cart-addresses" v-cloak v-else>
+                    <div class="bg-grey-100 p-1v cart-addresses" v-cloak v-show="cartItemCount === cartItemHasPriceCount">
                         <h2 class="font-normal">{{ __('Choisir une adresse de facturation') }} :</h2>
                         <form class="mb-12">
                             <div class="grid grid-cols-2 grid-gap-lg grid-rows-0 mb-3">
index 49d5733078720ca2024ed49da0b15dd1cad575ee..97c9969471f67a83c7d055073ac9cbe2a9dbeedf 100644 (file)
@@ -78,7 +78,7 @@
                         {{ __('Valider la commande') }}
                     </link-button>
                     <div class="text-center">
-                        <a href="" class="animated-underline mt-5 inline-block w-100">{{ __('Obtenir un devis officiel') }}</a><br>
+                        <a href="{{ $nav->getHrefByName('cart') }}" class="animated-underline mt-5 inline-block w-100">{{ __('Obtenir un devis officiel') }}</a><br>
                         <a href="" class="animated-underline mt-5 inline-block" @click.prevent="storeCart()">{{ __('Enregistrer ce panier') }}</a>
                     </div>
                 </div>