diff --git a/src/Service/MollieApi/OrderDataExtractor.php b/src/Service/MollieApi/OrderDataExtractor.php index 9d468f896..4f84a5dd8 100644 --- a/src/Service/MollieApi/OrderDataExtractor.php +++ b/src/Service/MollieApi/OrderDataExtractor.php @@ -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; @@ -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(); @@ -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( + [ + $this->buildFlat($lineItems) + ] + ); + } + + /** + * @param LineItemCollection $lineItems + * @return array + */ + private function buildFlat(LineItemCollection $lineItems): array + { + $flat = []; + foreach ($lineItems as $lineItem) { + $flat[] = $lineItem; + + foreach ($this->buildFlat($lineItem->getChildren()) as $nest) { + $flat[] = $nest; + } + } + + return $flat; } }