Skip to content

Commit

Permalink
NTR: PISHPS-338: Fix line items with custom products
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitalij Mik committed Aug 29, 2024
1 parent 38dbe33 commit 87f40dd
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions src/Service/MollieApi/Builder/MollieLineItemBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';


/**
Expand Down Expand Up @@ -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();
Expand All @@ -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());
}

Expand Down

0 comments on commit 87f40dd

Please sign in to comment.