From 5436200b4bad694789fbd9c66b7bc6bfdfcb99e9 Mon Sep 17 00:00:00 2001 From: Vitalij Mik Date: Thu, 29 Aug 2024 10:17:57 +0200 Subject: [PATCH] PISHPS-338: Fix line items with custom products (#819) * NTR: PISHPS-338: Fix line items with custom products * NTR: CS fix --------- Co-authored-by: Vitalij Mik --- .../Builder/MollieLineItemBuilder.php | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/Service/MollieApi/Builder/MollieLineItemBuilder.php b/src/Service/MollieApi/Builder/MollieLineItemBuilder.php index cb8bfda6f..cbfe098ee 100644 --- a/src/Service/MollieApi/Builder/MollieLineItemBuilder.php +++ b/src/Service/MollieApi/Builder/MollieLineItemBuilder.php @@ -24,6 +24,7 @@ class MollieLineItemBuilder { public const LINE_ITEM_TYPE_CUSTOM_PRODUCTS = 'customized-products'; + public const LINE_ITEM_TYPE_CUSTOM_PRODUCTS_OPTIONS = 'customized-products-option'; /** @@ -138,12 +139,27 @@ public function buildLineItems(string $taxStatus, ?OrderLineItemCollection $line { $lines = new MollieLineItemCollection(); - if (!$lineItems instanceof OrderLineItemCollection || $lineItems->count() === 0) { + if (! $lineItems instanceof OrderLineItemCollection || $lineItems->count() === 0) { return $lines; } foreach ($lineItems as $item) { + + /** Filter out the product from customized products plugin */ + if ($item->getType() === self::LINE_ITEM_TYPE_CUSTOM_PRODUCTS) { + $lineItemChildren = $item->getChildren(); + + if ($lineItemChildren instanceof OrderLineItemCollection && $lineItemChildren->count() > 0) { + $filteredItems = $lineItemChildren->filter(function (OrderLineItemEntity $lineItemEntity) { + return $lineItemEntity->getType() !== self::LINE_ITEM_TYPE_CUSTOM_PRODUCTS_OPTIONS; + }); + + if ($filteredItems instanceof OrderLineItemCollection && $filteredItems->count() === 1) { + $item = $filteredItems->first(); + } + } + } $this->orderLineItemValidator->validate($item); $extraData = $this->lineItemDataExtractor->extractExtraData($item); $itemPrice = $item->getPrice(); @@ -153,7 +169,7 @@ public function buildLineItems(string $taxStatus, ?OrderLineItemCollection $line $item->setQuantity(1); } - if (!$itemPrice instanceof CalculatedPrice) { + if (! $itemPrice instanceof CalculatedPrice) { throw new MissingPriceLineItemException((string)$item->getProductId()); }