Skip to content

Commit

Permalink
MOL-1235: Fix voucher recognition in bundles
Browse files Browse the repository at this point in the history
  • Loading branch information
boxblinkracer committed Oct 23, 2023
1 parent 76c8123 commit 5c813cf
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion src/Service/MollieApi/OrderDataExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Kiener\MolliePayments\Exception\OrderLineItemsNotFoundException;
use Kiener\MolliePayments\Service\CustomerService;
use Psr\Log\LoggerInterface;
use Shopware\Core\Checkout\Cart\LineItem\LineItemCollection;
use Shopware\Core\Checkout\Customer\CustomerEntity;
use Shopware\Core\Checkout\Order\Aggregate\OrderCustomer\OrderCustomerEntity;
use Shopware\Core\Checkout\Order\Aggregate\OrderDelivery\OrderDeliveryCollection;
Expand Down Expand Up @@ -140,6 +141,11 @@ public function extractDelivery(OrderEntity $orderEntity, Context $context): Ord
return $delivery;
}

/**
* @param OrderEntity $orderEntity
* @param Context $context
* @return OrderLineItemCollection
*/
public function extractLineItems(OrderEntity $orderEntity, Context $context): OrderLineItemCollection
{
$lineItems = $orderEntity->getLineItems();
Expand All @@ -152,6 +158,30 @@ public function extractLineItems(OrderEntity $orderEntity, Context $context): Or
throw new OrderLineItemsNotFoundException($orderEntity->getId());
}

return $lineItems;
# we have to build a flat list
# so that we also check nested items in bundles for instance
return new OrderLineItemCollection(
[

Check failure on line 164 in src/Service/MollieApi/OrderDataExtractor.php

View workflow job for this annotation

GitHub Actions / PHPStan

Parameter #1 $elements of class Shopware\Core\Checkout\Order\Aggregate\OrderLineItem\OrderLineItemCollection constructor expects iterable<Shopware\Core\Checkout\Order\Aggregate\OrderLineItem\OrderLineItemEntity>, array<int, array> given.
$this->buildFlat($lineItems)

Check failure on line 165 in src/Service/MollieApi/OrderDataExtractor.php

View workflow job for this annotation

GitHub Actions / PHPStan

Parameter #1 $lineItems of method Kiener\MolliePayments\Service\MollieApi\OrderDataExtractor::buildFlat() expects Shopware\Core\Checkout\Cart\LineItem\LineItemCollection, Shopware\Core\Checkout\Order\Aggregate\OrderLineItem\OrderLineItemCollection given.
]
);
}

/**
* @param LineItemCollection $lineItems
* @return array
*/
private function buildFlat(LineItemCollection $lineItems): array

Check failure on line 174 in src/Service/MollieApi/OrderDataExtractor.php

View workflow job for this annotation

GitHub Actions / PHPStan

Method Kiener\MolliePayments\Service\MollieApi\OrderDataExtractor::buildFlat() return type has no value type specified in iterable type array.
{
$flat = [];
foreach ($lineItems as $lineItem) {
$flat[] = $lineItem;

foreach ($this->buildFlat($lineItem->getChildren()) as $nest) {
$flat[] = $nest;
}
}

return $flat;
}
}

0 comments on commit 5c813cf

Please sign in to comment.