diff --git a/src/Service/MollieApi/Builder/MollieLineItemBuilder.php b/src/Service/MollieApi/Builder/MollieLineItemBuilder.php index cb8bfda6f..ecbc11f19 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,31 @@ 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 +173,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()); }