Skip to content

Commit

Permalink
PISHPS-338: Fix line items with custom products (#819)
Browse files Browse the repository at this point in the history
* NTR: PISHPS-338: Fix line items with custom products

* NTR: CS fix

---------

Co-authored-by: Vitalij Mik <[email protected]>
  • Loading branch information
BlackScorp and Vitalij Mik authored Aug 29, 2024
1 parent 38dbe33 commit 5436200
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 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,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();
Expand All @@ -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());
}

Expand Down

0 comments on commit 5436200

Please sign in to comment.