Skip to content

Commit

Permalink
Merge pull request #152 from vippsas/publication-2.4.39
Browse files Browse the repository at this point in the history
VIPPS-419: Added support for configurable items for send receipt service
  • Loading branch information
voleye authored Nov 9, 2022
2 parents bf50d71 + 52645c6 commit 8ef8320
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
16 changes: 12 additions & 4 deletions Gateway/Request/SendReceipt/OrderLinesBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand All @@ -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()
Expand All @@ -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];
}

Expand Down
2 changes: 1 addition & 1 deletion etc/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
~ IN THE SOFTWARE.
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Vipps_Payment" setup_version="2.4.38">
<module name="Vipps_Payment" setup_version="2.4.39">
<sequence>
<module name="Magento_Sales" />
<module name="Magento_Payment" />
Expand Down

0 comments on commit 8ef8320

Please sign in to comment.