Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PISHPS-338: Fix line items with custom products #819

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading