From ac69bf8c4f192bc34699122b997f34e3cc5c1cc4 Mon Sep 17 00:00:00 2001 From: Marvin Besselsen Date: Mon, 26 Feb 2024 16:19:38 +0100 Subject: [PATCH 1/4] Fix issue with wrong shipment method in checkout --- view/frontend/requirejs-config.js | 9 +++ .../web/js/view/shipping-information-ext.js | 78 +++++++++++++++++++ .../web/template/shipping-information.html | 37 +++++++++ 3 files changed, 124 insertions(+) create mode 100755 view/frontend/web/js/view/shipping-information-ext.js create mode 100755 view/frontend/web/template/shipping-information.html diff --git a/view/frontend/requirejs-config.js b/view/frontend/requirejs-config.js index 2a4bf5c..873f30b 100755 --- a/view/frontend/requirejs-config.js +++ b/view/frontend/requirejs-config.js @@ -4,6 +4,12 @@ */ var config = { + map: { + '*': { + 'Magento_InventoryInStorePickupFrontend/js/view/shipping-information-ext': 'Paazl_CheckoutWidget/js/view/shipping-information-ext' + }, + }, + config: { mixins: { 'Magento_Checkout/js/action/set-shipping-information': { @@ -42,6 +48,9 @@ var config = { 'Magento_SalesRule/js/action/set-coupon-code': { 'Paazl_CheckoutWidget/js/mixins/Magento_SalesRule/action/set-coupon-code-mixin': true }, + 'Magento_SalesRule/js/action/cancel-coupon': { + 'Paazl_CheckoutWidget/js/mixins/Magento_SalesRule/action/cancel-coupon-mixin': true + }, 'Magento_SalesRule/js/action/cancel-coupon': { 'Paazl_CheckoutWidget/js/mixins/Magento_SalesRule/action/cancel-coupon-mixin': true } diff --git a/view/frontend/web/js/view/shipping-information-ext.js b/view/frontend/web/js/view/shipping-information-ext.js new file mode 100755 index 0000000..ad8370a --- /dev/null +++ b/view/frontend/web/js/view/shipping-information-ext.js @@ -0,0 +1,78 @@ +/** + * Copyright © Paazl. All rights reserved. + * See COPYING.txt for license details. + */ + +define([ + 'Magento_Checkout/js/model/quote' +], function (quote) { + 'use strict'; + + var storePickupShippingInformation = { + defaults: { + template: 'Paazl_CheckoutWidget/shipping-information', + shippingMethodTitle: '', + }, + + initObservable: function () { + this._super().observe(['shippingMethodTitle']); + return this; + }, + + /** + * Get shipping method title based on delivery method. + * + * @return {String} + */ + getShippingMethodTitle: function () { + this.shippingMethodTitle(''); + + quote.totals.subscribe(() => { + var shippingMethod = quote.shippingMethod(), + locationName = '', + title; + + if (window.checkoutConfig.totalsData.extension_attributes[0]) { + shippingMethod = window.checkoutConfig.totalsData.extension_attributes[0]; + this.shippingMethodTitle(shippingMethod['carrier_title'] + ' - ' + shippingMethod['method_title']); + } else { + shippingMethod = quote.shippingMethod(); + + if (!this.isStorePickup()) { + return this._super(); + } + + title = shippingMethod['carrier_title'] + ' - ' + shippingMethod['method_title']; + + if (quote.shippingAddress().firstname !== undefined) { + locationName = quote.shippingAddress().firstname + ' ' + quote.shippingAddress().lastname; + title += ' "' + locationName + '"'; + } + + return title; + } + }); + }, + + /** + * Get is store pickup delivery method selected. + * + * @returns {Boolean} + */ + isStorePickup: function () { + var shippingMethod = quote.shippingMethod(), + isStorePickup = false; + + if (shippingMethod !== null) { + isStorePickup = shippingMethod['carrier_code'] === 'instore' && + shippingMethod['method_code'] === 'pickup'; + } + + return isStorePickup; + } + }; + + return function (shippingInformation) { + return shippingInformation.extend(storePickupShippingInformation); + }; +}); diff --git a/view/frontend/web/template/shipping-information.html b/view/frontend/web/template/shipping-information.html new file mode 100755 index 0000000..fcc380c --- /dev/null +++ b/view/frontend/web/template/shipping-information.html @@ -0,0 +1,37 @@ + + + +
+ +
+
+ + +
+
+ + + +
+
+ +
+
+ + +
+
+ +
+
+
+ From 52e5a4f19c9b6868eee81dfbf0774e709eba5cba Mon Sep 17 00:00:00 2001 From: Marvin Besselsen Date: Mon, 26 Feb 2024 16:20:35 +0100 Subject: [PATCH 2/4] Fix issue with saving pickup point address into address book --- .../web/js/checkout/view/shipping-mixin.js | 5 +++- .../web/template/shipping-address/form.html | 24 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100755 view/frontend/web/template/shipping-address/form.html diff --git a/view/frontend/web/js/checkout/view/shipping-mixin.js b/view/frontend/web/js/checkout/view/shipping-mixin.js index f85b1b0..68163f0 100755 --- a/view/frontend/web/js/checkout/view/shipping-mixin.js +++ b/view/frontend/web/js/checkout/view/shipping-mixin.js @@ -30,9 +30,12 @@ define([ return target.extend({ defaults: { shippingMethodListTemplate: 'Paazl_CheckoutWidget/checkout/shipping-method-list', - shippingMethodItemTemplate: 'Paazl_CheckoutWidget/checkout/shipping-method-item' + shippingMethodItemTemplate: 'Paazl_CheckoutWidget/checkout/shipping-method-item', + shippingFormTemplate: 'Paazl_CheckoutWidget/shipping-address/form', }, + saveInAddressBook: 0, + /** * @return {*} */ diff --git a/view/frontend/web/template/shipping-address/form.html b/view/frontend/web/template/shipping-address/form.html new file mode 100755 index 0000000..4d5300a --- /dev/null +++ b/view/frontend/web/template/shipping-address/form.html @@ -0,0 +1,24 @@ + +
+ + + +
+ + + + +
+ + +
+ +
+
From 053eace248e51f58d6fa895a32ff3720ad231d63 Mon Sep 17 00:00:00 2001 From: Marvin Besselsen Date: Mon, 26 Feb 2024 16:29:34 +0100 Subject: [PATCH 3/4] Added volume calculation option --- Model/Api/Builder/Order.php | 21 +++- Model/Checkout/WidgetConfigProvider.php | 96 +++++++++++++- Model/Config.php | 30 +++++ .../System/Config/Source/CalculateVolume.php | 55 ++++++++ .../System/Config/Source/DimensionsMetric.php | 50 ++++++++ etc/adminhtml/system.xml | 118 +++++++++++------- etc/config.xml | 1 + 7 files changed, 319 insertions(+), 52 deletions(-) create mode 100644 Model/System/Config/Source/CalculateVolume.php create mode 100644 Model/System/Config/Source/DimensionsMetric.php diff --git a/Model/Api/Builder/Order.php b/Model/Api/Builder/Order.php index 78c9d9c..ed871d1 100755 --- a/Model/Api/Builder/Order.php +++ b/Model/Api/Builder/Order.php @@ -20,6 +20,7 @@ use Paazl\CheckoutWidget\Model\Config; use Paazl\CheckoutWidget\Model\ExtInfoHandler; use Paazl\CheckoutWidget\Model\Handler\Item as ItemHandler; +use Paazl\CheckoutWidget\Model\System\Config\Source\DimensionsMetric; /** * Class Order @@ -387,19 +388,33 @@ private function getProductDimemension(Item $item) $dimensionArray = []; $product = $item->getProduct(); + switch ($this->scopeConfig->getDimensionsMetric()) { + case DimensionsMetric::METRIC_MM: + $k = 0.1; + break; + case DimensionsMetric::METRIC_CM: + $k = 1; + break; + case DimensionsMetric::METRIC_M: + $k = 100; + break; + default: + $k = 1; + } + if ($widthAttribute = $this->config->getProductAttributeWidth()) { - if ($width = $product->getData($widthAttribute)) { + if ($width = $product->getData($widthAttribute) * $k) { $dimensionArray['width'] = (int)$width; } } if ($heightAttribute = $this->config->getProductAttributeHeight()) { - if ($height = $product->getData($heightAttribute)) { + if ($height = $product->getData($heightAttribute) * $k) { $dimensionArray['height'] = (int)$height; } } - if ($lengthAttribute = $this->config->getProductAttributeLength()) { + if ($lengthAttribute = $this->config->getProductAttributeLength() * $k) { if ($length = $product->getData($lengthAttribute)) { $dimensionArray['length'] = (int)$length; } diff --git a/Model/Checkout/WidgetConfigProvider.php b/Model/Checkout/WidgetConfigProvider.php index 40ea1d1..c46fbe9 100755 --- a/Model/Checkout/WidgetConfigProvider.php +++ b/Model/Checkout/WidgetConfigProvider.php @@ -16,6 +16,8 @@ use Paazl\CheckoutWidget\Helper\General as GeneralHelper; use Paazl\CheckoutWidget\Model\Config; use Paazl\CheckoutWidget\Model\Handler\Item as ItemHandler; +use Paazl\CheckoutWidget\Model\System\Config\Source\CalculateVolume; +use Paazl\CheckoutWidget\Model\System\Config\Source\DimensionsMetric; use Paazl\CheckoutWidget\Model\TokenRetriever; /** @@ -118,12 +120,14 @@ public function getConfig() } $goods = []; + $widthAttribute = $this->scopeConfig->getProductAttributeWidth(); $heightAttribute = $this->scopeConfig->getProductAttributeHeight(); $lengthAttribute = $this->scopeConfig->getProductAttributeLength(); $useDimensions = $widthAttribute || $lengthAttribute || $heightAttribute; foreach ($this->getQuote()->getAllItems() as $item) { if ($item->getProductType() == 'simple') { + $product = $this->productRepository->getById($item->getProduct()->getId()); $goodsItem = [ "quantity" => $item->getParentItem() ? (int)($item->getParentItem()->getQty()) @@ -132,10 +136,28 @@ public function getConfig() "price" => $this->itemHandler->getPriceValue($item) ]; if ($useDimensions) { - $product = $this->productRepository->getById($item->getProduct()->getId()); - $goodsItem["length"] = (float)$product->getData($lengthAttribute); - $goodsItem["width"] = (float)$product->getData($widthAttribute); - $goodsItem["height"] = (float)$product->getData($heightAttribute); + switch ($this->scopeConfig->getDimensionsMetric()) { + case DimensionsMetric::METRIC_MM: + $k = 0.1; + break; + case DimensionsMetric::METRIC_CM: + $k = 1; + break; + case DimensionsMetric::METRIC_M: + $k = 100; + break; + default: + $k = 1; + } + $goodsItem["length"] = + (float)str_replace(',', '.', $product->getData($lengthAttribute)) * $k; + $goodsItem["width"] = + (float)str_replace(',', '.', $product->getData($widthAttribute)) * $k; + $goodsItem["height"] = + (float)str_replace(',', '.', $product->getData($heightAttribute)) * $k; + } + if ($this->scopeConfig->addVolume()) { + $goodsItem["volume"] = $this->getProductVolume($product); } if ($deliveryMatrixCode = $this->getProductDeliveryMatrix($item)) { @@ -202,6 +224,10 @@ public function getConfig() $config['shipmentParameters']['startMatrix'] = $this->getFreeShippingMatrixLetter(); } + if ($this->scopeConfig->addVolume()) { + $config['shipmentParameters']['totalVolume'] = $this->getTotalVolume($goods); + } + switch ($this->scopeConfig->getTotalPrice()) { case "grand_total": $totalPriceValue = (float) $shippingAddress->getGrandTotal() - @@ -356,6 +382,21 @@ public function getTotalWeight($goods) return $weight; } + /** + * @return float + */ + public function getTotalVolume($goods): float + { + $volume = 0; + $quote = $this->getQuote(); + foreach ($goods as $good) { + if (isset($good['volume']) && isset($good['quantity'])) { + $volume += ($good['volume'] * $good['quantity']); + } + } + return (float)$volume; + } + /** * @return float */ @@ -490,4 +531,51 @@ protected function isFreeShippingEnabled() { return $this->scopeConfig->isFreeShippingEnabled($this->getQuote()->getStoreId()); } + + /** + * @param $product + * @return float + */ + private function getProductVolume($product): float + { + switch ($this->scopeConfig->addVolume()) { + case CalculateVolume::CALCULATE_VOLUME_USE_ATTRIBUTE: + return $product->getData($this->scopeConfig->getProductAttributeVolume()); + case CalculateVolume::CALCULATE_VOLUME_CALCULATE: + return $this->calculateVolumeByDimensions($product); + case CalculateVolume::CALCULATE_VOLUME_CALCULATE_IF_MISSED: + return $product->getData($this->scopeConfig->getProductAttributeVolume()) ?: + $this->calculateVolumeByDimensions($product); + } + } + + /** + * Calculate volume in m^3 using dimensions in cm + * + * @param $product + * @return float + */ + private function calculateVolumeByDimensions($product): float + { + switch ($this->scopeConfig->getDimensionsMetric()) { + case DimensionsMetric::METRIC_MM: + $k = 0.000000001; + break; + case DimensionsMetric::METRIC_CM: + $k = 0.000001; + break; + case DimensionsMetric::METRIC_M: + $k = 1; + break; + default: + $k = 0.000001; + } + $widthAttribute = $this->scopeConfig->getProductAttributeWidth(); + $heightAttribute = $this->scopeConfig->getProductAttributeHeight(); + $lengthAttribute = $this->scopeConfig->getProductAttributeLength(); + return (float)str_replace(',', '.', $product->getData($widthAttribute)) * + (float)str_replace(',', '.', $product->getData($heightAttribute)) * + (float)str_replace(',', '.', $product->getData($lengthAttribute)) * + $k; + } } diff --git a/Model/Config.php b/Model/Config.php index 1b9fd53..617050f 100644 --- a/Model/Config.php +++ b/Model/Config.php @@ -379,6 +379,16 @@ public function getCustomDescription($store = null) return $this->getValue(self::API_CONFIG_PATH . '/custom_description', $store); } + /** + * @param null|Store|int|string $store + * + * @return mixed + */ + public function getDimensionsMetric($store = null) + { + return $this->getValue(self::API_CONFIG_PATH . '/dimensions_metric', $store); + } + /** * @param null|Store|int|string $store * @@ -409,6 +419,26 @@ public function getProductAttributeHeight($store = null) return $this->getValue(self::API_CONFIG_PATH . '/height_attribute', $store); } + /** + * @param null|Store|int|string $store + * + * @return mixed + */ + public function getProductAttributeVolume($store = null) + { + return $this->getValue(self::API_CONFIG_PATH . '/volume_attribute', $store); + } + + /** + * @param null|Store|int|string $store + * + * @return mixed + */ + public function addVolume($store = null) + { + return $this->getValue(self::API_CONFIG_PATH . '/add_volume', $store); + } + /** * @param null|Store|int|string $store * diff --git a/Model/System/Config/Source/CalculateVolume.php b/Model/System/Config/Source/CalculateVolume.php new file mode 100644 index 0000000..bc34d41 --- /dev/null +++ b/Model/System/Config/Source/CalculateVolume.php @@ -0,0 +1,55 @@ +options) { + $this->options = [ + [ + 'value' => self::CALCULATE_VOLUME_NO, + 'label' => __('No') + ], + [ + 'value' => self::CALCULATE_VOLUME_USE_ATTRIBUTE, + 'label' => __('Yes, use volume attribute') + ], + [ + 'value' => self::CALCULATE_VOLUME_CALCULATE, + 'label' => __('Yes, always calculate using dimensions') + ], + [ + 'value' => self::CALCULATE_VOLUME_CALCULATE_IF_MISSED, + 'label' => __('Yes, calculate using dimensions if volume missed') + ] + ]; + } + + return $this->options; + } +} diff --git a/Model/System/Config/Source/DimensionsMetric.php b/Model/System/Config/Source/DimensionsMetric.php new file mode 100644 index 0000000..91b4c6e --- /dev/null +++ b/Model/System/Config/Source/DimensionsMetric.php @@ -0,0 +1,50 @@ +options) { + $this->options = [ + [ + 'value' => self::METRIC_MM, + 'label' => __('mm') + ], + [ + 'value' => self::METRIC_CM, + 'label' => __('cm') + ], + [ + 'value' => self::METRIC_M, + 'label' => __('m') + ] + ]; + } + + return $this->options; + } +} diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index c802c9c..5e7e023 100755 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -178,128 +178,156 @@ Paazl\CheckoutWidget\Block\Adminhtml\Paazl\Heading - - - Magento\Config\Model\Config\Source\Yesno - By default the product name is used as description. Set to yes, to use a custom value for item description. - - - - - 1 - - - - - Paazl\CheckoutWidget\Model\System\Config\Source\Attributes - The length specified in the selected product definition. - - - - Paazl\CheckoutWidget\Model\System\Config\Source\Attributes - The width specified in the selected product definition. - - - - Paazl\CheckoutWidget\Model\System\Config\Source\Attributes - The height specified in the selected product definition. - - + Paazl\CheckoutWidget\Model\System\Config\Source\Attributes The number of days a warehouse needs to get an order ready for pick-up by a carrier. - + Paazl\CheckoutWidget\Model\System\Config\Source\AttributesWithStatic This setting is only required for international shipments. - + This value applies to all products. paazl-static-option - + Paazl\CheckoutWidget\Model\System\Config\Source\AttributesWithStatic This setting is only required for international shipments - + This value applies to all products. paazl-static-option - + Paazl\CheckoutWidget\Model\System\Config\Source\Attributes delivery matrix column used to determine shipping option.]]> - + + + Magento\Config\Model\Config\Source\Yesno + By default the product name is used as description. Set to yes, to use a custom value for item description. + + + + + 1 + + + + + + + Paazl\CheckoutWidget\Block\Adminhtml\Paazl\Heading + + + + + Paazl\CheckoutWidget\Model\System\Config\Source\CalculateVolume + + + + + Paazl\CheckoutWidget\Model\System\Config\Source\Attributes + The volume specified in the selected product definition. + + + + + + + Paazl\CheckoutWidget\Model\System\Config\Source\Attributes + The length specified in the selected product definition. + + + + + Paazl\CheckoutWidget\Model\System\Config\Source\Attributes + The width specified in the selected product definition. + + + + Paazl\CheckoutWidget\Model\System\Config\Source\Attributes + The height specified in the selected product definition. + + + + + Paazl\CheckoutWidget\Model\System\Config\Source\DimensionsMetric + Please specify the metric you us, as we will automatically calculate values based on your selection. + + + Paazl\CheckoutWidget\Block\Adminhtml\Paazl\Heading - + Paazl\CheckoutWidget\Model\System\Config\Source\SyncMethod Choose method to push orders to API. - + Time threshold in seconds after which API is treated as not responding. validate-not-negative-number integer - + Magento\Config\Model\Config\Source\Yesno Choose whether you want to use your own Google MAP API key or Paazl's inbuilt key. - + 1 Google Account]]> - + Paazl\CheckoutWidget\Model\System\Config\Source\TotalPrice Select the price which will be used for totalPrice. - + Magento\Config\Model\Config\Source\Yesno - + 1 - + Magento\Config\Model\Config\Source\Yesno If yes - shipping price will always includes tax regardless Magento settings - + Magento\Config\Model\Config\Source\Yesno Write API calls to var/log/paazl.log. Not recommended in Paazl's production environment for performance reasons. - + - + Magento\Config\Model\Config\Source\Yesno OneStepCheckout, Custom Checkout etc. - + Magento\Config\Model\Config\Source\Yesno Local copy will be used instead of external JS (from *.paazl.com). diff --git a/etc/config.xml b/etc/config.xml index b2d9b9d..51f4440 100644 --- a/etc/config.xml +++ b/etc/config.xml @@ -36,6 +36,7 @@ 1 subtotal_incl_discount 0 + cm From 69ec04ca67cd9f301cfafab9980f8d8954ab384e Mon Sep 17 00:00:00 2001 From: Marvin Besselsen Date: Mon, 26 Feb 2024 16:30:35 +0100 Subject: [PATCH 4/4] Version bump --- composer.json | 2 +- etc/config.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index d4c50f1..bb5fb38 100755 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "paazl/magento2-checkout-widget", "description": "Paazl checkoutWidget for Magento 2", "type": "magento2-module", - "version": "1.15.1", + "version": "1.16.0", "keywords": [ "Paazl", "Magento 2", diff --git a/etc/config.xml b/etc/config.xml index 51f4440..94ef55a 100644 --- a/etc/config.xml +++ b/etc/config.xml @@ -8,7 +8,7 @@ - v1.15.1 + v1.16.0 0 0 0