From 2fb620438a85f4c2e5ded26e74cea2ac1b000971 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Re=C3=A9nse?= Date: Tue, 26 Oct 2021 11:30:27 +0200 Subject: [PATCH 1/6] Fix: API does not accept strings as length/width/height. Added explicit cast so integers are always returned. --- Model/Checkout/WidgetConfigProvider.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Model/Checkout/WidgetConfigProvider.php b/Model/Checkout/WidgetConfigProvider.php index dffeb7b..750830f 100644 --- a/Model/Checkout/WidgetConfigProvider.php +++ b/Model/Checkout/WidgetConfigProvider.php @@ -140,9 +140,9 @@ public function getConfig() ]; if ($useDimensions) { $product = $this->productRepository->getById($item->getProduct()->getId()); - $goodsItem["length"] = $product->getData($lengthAttribute); - $goodsItem["width"] = $product->getData($widthAttribute); - $goodsItem["height"] = $product->getData($heightAttribute); + $goodsItem["length"] = (int) $product->getData($lengthAttribute); + $goodsItem["width"] = (int) $product->getData($widthAttribute); + $goodsItem["height"] = (int) $product->getData($heightAttribute); } if (($itemNumberOfProcessingDays = $this->getProductNumberOfProcessingDays($item)) From 0be4532e2217f31bf166f0c71f05e00775d6f425 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Re=C3=A9nse?= Date: Tue, 26 Oct 2021 11:31:36 +0200 Subject: [PATCH 2/6] Change integer-casts to float-casts. --- Model/Checkout/WidgetConfigProvider.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Model/Checkout/WidgetConfigProvider.php b/Model/Checkout/WidgetConfigProvider.php index 750830f..63bad93 100644 --- a/Model/Checkout/WidgetConfigProvider.php +++ b/Model/Checkout/WidgetConfigProvider.php @@ -140,9 +140,9 @@ public function getConfig() ]; if ($useDimensions) { $product = $this->productRepository->getById($item->getProduct()->getId()); - $goodsItem["length"] = (int) $product->getData($lengthAttribute); - $goodsItem["width"] = (int) $product->getData($widthAttribute); - $goodsItem["height"] = (int) $product->getData($heightAttribute); + $goodsItem["length"] = (float) $product->getData($lengthAttribute); + $goodsItem["width"] = (float) $product->getData($widthAttribute); + $goodsItem["height"] = (float) $product->getData($heightAttribute); } if (($itemNumberOfProcessingDays = $this->getProductNumberOfProcessingDays($item)) From 00232f8e483c4f302ee24c80d35a3258f27abb49 Mon Sep 17 00:00:00 2001 From: Marvin-Magmodules Date: Mon, 1 Nov 2021 13:47:51 +0100 Subject: [PATCH 3/6] Only add simple products to goods line --- Model/Checkout/WidgetConfigProvider.php | 39 ++++++++++++------------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/Model/Checkout/WidgetConfigProvider.php b/Model/Checkout/WidgetConfigProvider.php index 63bad93..6395038 100644 --- a/Model/Checkout/WidgetConfigProvider.php +++ b/Model/Checkout/WidgetConfigProvider.php @@ -131,29 +131,26 @@ public function getConfig() $widthAttribute = $this->scopeConfig->getProductAttributeWidth(); $heightAttribute = $this->scopeConfig->getProductAttributeHeight(); $lengthAttribute = $this->scopeConfig->getProductAttributeLength(); - $useDimensions = $widthAttribute && $lengthAttribute && $heightAttribute; - foreach ($this->getQuote()->getAllVisibleItems() as $item) { - $goodsItem = [ - "quantity" => (int)$item->getQty(), - "weight" => doubleval($item->getWeight()), - "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); - } - - if (($itemNumberOfProcessingDays = $this->getProductNumberOfProcessingDays($item)) - && $itemNumberOfProcessingDays > $numberOfProcessingDays) { - $numberOfProcessingDays = (int)$itemNumberOfProcessingDays; - } + $useDimensions = $widthAttribute || $lengthAttribute || $heightAttribute; + foreach ($this->getQuote()->getAllItems() as $item) { + if ($item->getProductType() == 'simple') { + $goodsItem = [ + "quantity" => (int)$item->getQty(), + "weight" => doubleval($item->getWeight()), + "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); + } - if ($deliveryMatrixCode = $this->getProductDeliveryMatrix($item)) { - $goodsItem["startMatrix"] = $deliveryMatrixCode; + if ($deliveryMatrixCode = $this->getProductDeliveryMatrix($item)) { + $goodsItem["startMatrix"] = $deliveryMatrixCode; + } + $goods[] = $goodsItem; } - $goods[] = $goodsItem; } $config = [ From 45725942b78f03d25082044e73d50daf5dd14cde Mon Sep 17 00:00:00 2001 From: Marvin-Magmodules Date: Mon, 1 Nov 2021 13:50:32 +0100 Subject: [PATCH 4/6] ProductData for bundle products sends the total bundle price for each child item to API --- Model/Api/Builder/Order.php | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/Model/Api/Builder/Order.php b/Model/Api/Builder/Order.php index 1ba16e5..64e8f50 100755 --- a/Model/Api/Builder/Order.php +++ b/Model/Api/Builder/Order.php @@ -293,7 +293,15 @@ private function getProducts(OrderInterface $order) /** @var Item $item */ foreach ($order->getItems() as $item) { - if ($item->getProductType() !== Type::TYPE_SIMPLE && $item->getProductType() !== Grouped::TYPE_CODE) { + if ($item->getProductType() !== Type::TYPE_SIMPLE + && $item->getProductType() !== Type::TYPE_BUNDLE + && $item->getProductType() !== Grouped::TYPE_CODE + ) { + continue; + } + + // Skip a simple product if the parent is a bundle + if ($this->hasBundleParent($item)) { continue; } @@ -399,4 +407,18 @@ private function getProductDimemension(Item $item) return $dimensionArray; } + + /** + * Check if parent item is bundle + * + * @param $item + * @return bool + */ + private function hasBundleParent($item): bool + { + if ($item->getParentItemId() > 0) { + return $item->getParentItem()->getProductType() === Type::TYPE_BUNDLE; + } + return false; + } } From 49cda29dcc0775b188ef4d06a0e47317e5bdd51a Mon Sep 17 00:00:00 2001 From: Marvin-Magmodules Date: Mon, 1 Nov 2021 13:52:12 +0100 Subject: [PATCH 5/6] Processing days do not work on simple level --- Model/Checkout/WidgetConfigProvider.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Model/Checkout/WidgetConfigProvider.php b/Model/Checkout/WidgetConfigProvider.php index 6395038..42268df 100644 --- a/Model/Checkout/WidgetConfigProvider.php +++ b/Model/Checkout/WidgetConfigProvider.php @@ -126,7 +126,6 @@ public function getConfig() $postcode = $shippingAddress->getPostcode(); } - $numberOfProcessingDays = self::DEFAULT_NUMBER_OF_PROCESSING_DAYS; $goods = []; $widthAttribute = $this->scopeConfig->getProductAttributeWidth(); $heightAttribute = $this->scopeConfig->getProductAttributeHeight(); @@ -153,6 +152,19 @@ public function getConfig() } } + $numberOfProcessingDays = self::DEFAULT_NUMBER_OF_PROCESSING_DAYS; + foreach ($this->getQuote()->getAllItems() as $item) { + if ($item->getProductType() == 'simple') { + $itemNumberOfProcessingDays = $this->getProductNumberOfProcessingDays($item); + if (!$itemNumberOfProcessingDays && $item->getParentItem()) { + $itemNumberOfProcessingDays = $this->getProductNumberOfProcessingDays($item->getParentItem()); + } + if ($itemNumberOfProcessingDays && ($itemNumberOfProcessingDays > $numberOfProcessingDays)) { + $numberOfProcessingDays = (int)$itemNumberOfProcessingDays; + } + } + } + $config = [ "mountElementId" => "widget_paazlshipping_paazlshipping", "apiKey" => $this->getApiKey(), From 07f30dc55fd39ff57645b3369cc58f29d73da628 Mon Sep 17 00:00:00 2001 From: Marvin-Magmodules Date: Mon, 1 Nov 2021 13:52:51 +0100 Subject: [PATCH 6/6] 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 9ab1326..d719294 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.9.1", + "version": "1.9.2", "keywords": [ "Paazl", "Magento 2", diff --git a/etc/config.xml b/etc/config.xml index de60858..cd07cf2 100644 --- a/etc/config.xml +++ b/etc/config.xml @@ -8,7 +8,7 @@ - v1.9.1 + v1.9.2 0 0 0