From: soufiane Date: Mon, 17 Jul 2023 09:34:35 +0000 (+0200) Subject: wait #6123 @8:30 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=168dd420796b4431269fab013a2878b7c058a5ad;p=pmi.git wait #6123 @8:30 --- diff --git a/app/Http/Controllers/Admin/ProductBaseController.php b/app/Http/Controllers/Admin/ProductBaseController.php index 8fcfb5a..4d6f8dd 100644 --- a/app/Http/Controllers/Admin/ProductBaseController.php +++ b/app/Http/Controllers/Admin/ProductBaseController.php @@ -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"); }); } } diff --git a/app/Http/Controllers/AjaxController.php b/app/Http/Controllers/AjaxController.php index 70c0165..f4d7168 100644 --- a/app/Http/Controllers/AjaxController.php +++ b/app/Http/Controllers/AjaxController.php @@ -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' diff --git a/app/Models/Client.php b/app/Models/Client.php index d693c92..b1b2025 100644 --- a/app/Models/Client.php +++ b/app/Models/Client.php @@ -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; + } } diff --git a/app/Models/ECommerceCommon.php b/app/Models/ECommerceCommon.php index a89a349..91aa2c4 100644 --- a/app/Models/ECommerceCommon.php +++ b/app/Models/ECommerceCommon.php @@ -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)); diff --git a/app/Models/Product.php b/app/Models/Product.php index 48875f4..83c4ab1 100644 --- a/app/Models/Product.php +++ b/app/Models/Product.php @@ -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 = []) { diff --git a/resources/js/app.js b/resources/js/app.js index 8bc2cb0..c7db50e 100644 --- a/resources/js/app.js +++ b/resources/js/app.js @@ -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() { + } }, /** diff --git a/resources/js/mailform.js b/resources/js/mailform.js index c49c047..e80cce0 100644 --- a/resources/js/mailform.js +++ b/resources/js/mailform.js @@ -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(`

${$(form).data('confirmation')}

`); + + if($("#getQuote")) { + $("#getQuote").text($(form).data('confirmation')) + } + cubistga.handleGtag($(form).get(0)); }).catch((error) => { $(button).text(button.data('text')).prop('disabled', false); diff --git a/resources/views/pages/cart.blade.php b/resources/views/pages/cart.blade.php index a0f7664..4827683 100644 --- a/resources/views/pages/cart.blade.php +++ b/resources/views/pages/cart.blade.php @@ -30,7 +30,7 @@ @if(\App\Models\Client::getClientConnected()) @endif @@ -44,7 +44,7 @@
-
+
@form([ 'action' => '/ajax/request_quote', 'ga'=>false, @@ -52,7 +52,7 @@ ])
-
+

{{ __('Choisir une adresse de facturation') }} :

diff --git a/resources/views/partials/header.blade.php b/resources/views/partials/header.blade.php index 49d5733..97c9969 100644 --- a/resources/views/partials/header.blade.php +++ b/resources/views/partials/header.blade.php @@ -78,7 +78,7 @@ {{ __('Valider la commande') }}