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; + } } diff --git a/Model/Checkout/WidgetConfigProvider.php b/Model/Checkout/WidgetConfigProvider.php index dffeb7b..42268df 100644 --- a/Model/Checkout/WidgetConfigProvider.php +++ b/Model/Checkout/WidgetConfigProvider.php @@ -126,34 +126,43 @@ public function getConfig() $postcode = $shippingAddress->getPostcode(); } - $numberOfProcessingDays = self::DEFAULT_NUMBER_OF_PROCESSING_DAYS; $goods = []; $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"] = $product->getData($lengthAttribute); - $goodsItem["width"] = $product->getData($widthAttribute); - $goodsItem["height"] = $product->getData($heightAttribute); - } + $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 (($itemNumberOfProcessingDays = $this->getProductNumberOfProcessingDays($item)) - && $itemNumberOfProcessingDays > $numberOfProcessingDays) { - $numberOfProcessingDays = (int)$itemNumberOfProcessingDays; + if ($deliveryMatrixCode = $this->getProductDeliveryMatrix($item)) { + $goodsItem["startMatrix"] = $deliveryMatrixCode; + } + $goods[] = $goodsItem; } + } - if ($deliveryMatrixCode = $this->getProductDeliveryMatrix($item)) { - $goodsItem["startMatrix"] = $deliveryMatrixCode; + $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; + } } - $goods[] = $goodsItem; } $config = [ 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