From 52645c6afb20e1111ce410b3b7a5c550eb7a470a Mon Sep 17 00:00:00 2001 From: Volodymyr Klymenko Date: Wed, 9 Nov 2022 12:05:45 +0200 Subject: [PATCH] VIPPS-419: Added support for configurable items for send receipt service --- .../Request/SendReceipt/OrderLinesBuilder.php | 16 ++++++++++++---- etc/module.xml | 2 +- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/Gateway/Request/SendReceipt/OrderLinesBuilder.php b/Gateway/Request/SendReceipt/OrderLinesBuilder.php index 8281a4f..f5e42ef 100644 --- a/Gateway/Request/SendReceipt/OrderLinesBuilder.php +++ b/Gateway/Request/SendReceipt/OrderLinesBuilder.php @@ -15,6 +15,7 @@ */ namespace Vipps\Payment\Gateway\Request\SendReceipt; +use Magento\ConfigurableProduct\Model\Product\Type\Configurable; use Magento\Payment\Gateway\Request\BuilderInterface; use Magento\Sales\Api\Data\OrderInterface; use Magento\Sales\Model\Order; @@ -59,7 +60,11 @@ public function build(array $buildSubject) $orderLines = []; foreach ($order->getItemsCollection() as $item) { /** @var Order\Item $item */ - if ($item->getChildrenItems()) { + if (($item->getChildrenItems() && $item->getProductType() !== Configurable::TYPE_CODE) + || ($item->getParentItem() && $item->getParentItem()->getProductType() === Configurable::TYPE_CODE) + ) { + // it means we take into account only simple products that is not a part of configurable + // for configurable product we take into account main configurable product bu not its simples continue; } @@ -72,7 +77,9 @@ public function build(array $buildSubject) 'totalAmount' => (int)($totalAmount * 100), 'totalAmountExcludingTax' => (int)($totalAmountExcludingTax * 100), 'totalTaxAmount' => (int)($item->getTaxAmount() * 100), - 'taxPercentage' => (int)round($item->getTaxAmount() * 100 / $totalAmount), + 'taxPercentage' => $totalAmount > 0 + ? (int)round($item->getTaxAmount() * 100 / $totalAmount) + : $item->getTaxPercent(), 'unitInfo' => [ 'unitPrice' => (int)($item->getPrice() * 100), 'quantity' => (string)$item->getQtyOrdered() @@ -90,13 +97,14 @@ public function build(array $buildSubject) 'totalAmount' => (int)($order->getShippingInclTax() * 100), 'totalAmountExcludingTax' => (int)($order->getShippingAmount() * 100), 'totalTaxAmount' => (int)($order->getShippingTaxAmount() * 100), - 'taxPercentage' => (int)round($order->getShippingTaxAmount() * 100 / $order->getShippingInclTax()), + 'taxPercentage' => $order->getShippingInclTax() > 0 + ? (int)round($order->getShippingTaxAmount() * 100 / $order->getShippingInclTax()) + : 0, 'discount' => (int)($order->getShippingDiscountAmount() * 100), 'isReturn' => false, 'isShipping' => true ]; - return ['orderLines'=> $orderLines]; } diff --git a/etc/module.xml b/etc/module.xml index dff0e9d..1634aa0 100644 --- a/etc/module.xml +++ b/etc/module.xml @@ -14,7 +14,7 @@ ~ IN THE SOFTWARE. --> - +