From 7455e15797eb5f57b398dd8f63294a7a554ab211 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20Hochd=C3=B6rfer?= Date: Tue, 20 Jun 2023 20:06:53 +0200 Subject: [PATCH 1/8] Refactor AddToCartListener to CartItemFactory --- .../CartItemFactory.php} | 97 +++++++++++-------- .../config/app/services/eventListener.xml | 10 -- src/Resources/config/app/services/factory.xml | 14 +++ .../OrderItemCustomerOptionCapableTrait.php | 28 +++++- 4 files changed, 98 insertions(+), 51 deletions(-) rename src/{EventListener/AddToCartListener.php => Factory/CartItemFactory.php} (52%) diff --git a/src/EventListener/AddToCartListener.php b/src/Factory/CartItemFactory.php similarity index 52% rename from src/EventListener/AddToCartListener.php rename to src/Factory/CartItemFactory.php index e24c4136..cb2eaa2a 100644 --- a/src/EventListener/AddToCartListener.php +++ b/src/Factory/CartItemFactory.php @@ -10,45 +10,66 @@ */ declare(strict_types=1); -namespace Brille24\SyliusCustomerOptionsPlugin\EventListener; +namespace Brille24\SyliusCustomerOptionsPlugin\Factory; -use Brille24\SyliusCustomerOptionsPlugin\Entity\OrderItemInterface; use Brille24\SyliusCustomerOptionsPlugin\Enumerations\CustomerOptionTypeEnum; -use Brille24\SyliusCustomerOptionsPlugin\Factory\OrderItemOptionFactoryInterface; use Brille24\SyliusCustomerOptionsPlugin\Repository\CustomerOptionRepositoryInterface; -use Doctrine\ORM\EntityManagerInterface; -use Sylius\Bundle\ResourceBundle\Event\ResourceControllerEvent; +use Sylius\Component\Core\Factory\CartItemFactoryInterface; use Sylius\Component\Core\Model\OrderInterface; -use Sylius\Component\Order\Processor\OrderProcessorInterface; +use Sylius\Component\Core\Model\OrderItemInterface; +use Sylius\Component\Core\Model\ProductInterface; +use Sylius\Component\Product\Resolver\ProductVariantResolverInterface; +use Sylius\Component\Resource\Factory\FactoryInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\RequestStack; use Webmozart\Assert\Assert; -final class AddToCartListener +class CartItemFactory implements CartItemFactoryInterface { + private CartItemFactoryInterface $decoratedFactory; + private ProductVariantResolverInterface $variantResolver; + private RequestStack $requestStack; + private OrderItemOptionFactoryInterface $orderItemOptionFactory; + private CustomerOptionRepositoryInterface $customerOptionRepository; + public function __construct( - private RequestStack $requestStack, - private EntityManagerInterface $entityManager, - private OrderItemOptionFactoryInterface $orderItemOptionFactory, - private OrderProcessorInterface $orderProcessor, - private CustomerOptionRepositoryInterface $customerOptionRepository, - ) + FactoryInterface $decoratedFactory, + ProductVariantResolverInterface $variantResolver, + RequestStack $requestStack, + OrderItemOptionFactoryInterface $orderItemOptionFactory, + CustomerOptionRepositoryInterface $customerOptionRepository + ) { + $this->decoratedFactory = new \Sylius\Component\Core\Factory\CartItemFactory($decoratedFactory, $variantResolver); + $this->variantResolver = $variantResolver; + $this->requestStack = $requestStack; + $this->orderItemOptionFactory = $orderItemOptionFactory; + $this->customerOptionRepository = $customerOptionRepository; + } + + public function createForProduct(ProductInterface $product): OrderItemInterface { + return $this->decoratedFactory->createForProduct($product); } - public function addItemToCart(ResourceControllerEvent $event): void + public function createForCart(OrderInterface $order): OrderItemInterface { - /** @var OrderItemInterface $orderItem */ - $orderItem = $event->getSubject(); + return $this->decoratedFactory->createForCart($order); + } - // If the order is null, it's an old order item with an existing reference in the database - if ($orderItem->getOrder() === null) { - return; - } + public function createNew() + { + return $this->decoratedFactory->createNew(); + } + + public function createForProductWithCustomerOption(ProductInterface $product): OrderItemInterface + { + /** @var OrderItemInterface $cartItem */ + $cartItem = $this->createNew(); + $cartItem->setVariant($this->variantResolver->getVariant($product)); $request = $this->requestStack->getCurrentRequest(); if (!$request instanceof Request) { - return; + return $cartItem; } $customerOptionConfiguration = $this->getCustomerOptionsFromRequest($request); @@ -69,28 +90,26 @@ public function addItemToCart(ResourceControllerEvent $event): void foreach ($valueArray as $value) { // Creating the item $salesOrderConfiguration = $this->orderItemOptionFactory->createNewFromStrings( - $orderItem, + $cartItem, $customerOptionCode, - $value, + $value ); - $this->entityManager->persist($salesOrderConfiguration); - $salesOrderConfigurations[] = $salesOrderConfiguration; } } - $orderItem->setCustomerOptionConfiguration($salesOrderConfigurations); - /** @var OrderInterface $order */ - $order = $orderItem->getOrder(); - $this->orderProcessor->process($order); + $cartItem->setCustomerOptionConfiguration($salesOrderConfigurations); - $this->entityManager->persist($orderItem); - $this->entityManager->flush(); + return $cartItem; } /** * Gets the customer options from the request + * + * @param Request $request + * + * @return array */ public function getCustomerOptionsFromRequest(Request $request): array { @@ -109,20 +128,20 @@ public function getCustomerOptionsFromRequest(Request $request): array switch ($customerOption->getType()) { case CustomerOptionTypeEnum::DATE: - $day = $value['day']; - $month = $value['month']; - $year = $value['year']; + $day = $value['day']; + $month = $value['month']; + $year = $value['year']; $addToCart['customer_options'][$code] = sprintf('%d-%d-%d', $year, $month, $day); break; case CustomerOptionTypeEnum::DATETIME: - $date = $value['date']; - $time = $value['time']; - $day = $date['day']; + $date = $value['date']; + $time = $value['time']; + $day = $date['day']; $month = $date['month']; - $year = $date['year']; + $year = $date['year']; - $hour = $time['hour'] ?? 0; + $hour = $time['hour'] ?? 0; $minute = $time['minute'] ?? 0; $addToCart['customer_options'][$code] = sprintf('%d-%d-%d %d:%d', $year, $month, $day, $hour, $minute); diff --git a/src/Resources/config/app/services/eventListener.xml b/src/Resources/config/app/services/eventListener.xml index de61e445..6365ff12 100644 --- a/src/Resources/config/app/services/eventListener.xml +++ b/src/Resources/config/app/services/eventListener.xml @@ -1,15 +1,5 @@ - - - - - - - - - - + + + + + + + + diff --git a/src/Traits/OrderItemCustomerOptionCapableTrait.php b/src/Traits/OrderItemCustomerOptionCapableTrait.php index 1f485bdd..1d28b036 100644 --- a/src/Traits/OrderItemCustomerOptionCapableTrait.php +++ b/src/Traits/OrderItemCustomerOptionCapableTrait.php @@ -91,8 +91,32 @@ public function equals(SyliusOrderItemInterface $item): bool return false; } - $product = $item instanceof self ? $item->getProduct() : null; + if (!$item instanceof self) { + return false; + } + + /** @var OrderItemOptionInterface[] $itemCustomerConfiguration */ + $itemCustomerConfiguration = $item->getCustomerOptionConfiguration(true); + $curItemCustomerConfiguration = $this->getCustomerOptionConfiguration(true); + + // configuration array size needs to be identical + if (count($itemCustomerConfiguration) !== count($curItemCustomerConfiguration)) { + return false; + } + + // configuration array keys need to match + $diff = array_diff_key($itemCustomerConfiguration, $curItemCustomerConfiguration); + if (count($diff) !== 0) { + return false; + } + + // iterate over all options and compare their values + foreach ($itemCustomerConfiguration as $code => $value) { + if ($curItemCustomerConfiguration[$code]->getOptionValue() !== $value->getOptionValue()) { + return false; + } + } - return ($product instanceof ProductInterface) ? !$product->hasCustomerOptions() : true; + return true; } } From 1bf41e14b68766ea280bd49480dda82886141884 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20Hochd=C3=B6rfer?= Date: Thu, 28 Dec 2023 10:05:18 +0100 Subject: [PATCH 2/8] Extend README with the Sylius routes to overwrite --- README.md | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/README.md b/README.md index 1708cf0c..06640650 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,43 @@ imports: ```yaml brille24_customer_options: resource: "@Brille24SyliusCustomerOptionsPlugin/Resources/config/app/routing.yml" + +sylius_shop_ajax_cart_add_item: + path: ajax/cart/add + methods: [POST] + defaults: + _controller: sylius.controller.order_item::addAction + _format: json + _sylius: + factory: + method: createForProductWithCustomerOption + arguments: [expr:notFoundOnNull(service('sylius.repository.product').find($productId))] + form: + type: Sylius\Bundle\CoreBundle\Form\Type\Order\AddToCartType + options: + product: expr:notFoundOnNull(service('sylius.repository.product').find($productId)) + redirect: + route: sylius_shop_cart_summary + parameters: {} + flash: sylius.cart.add_item + +sylius_shop_partial_cart_add_item: + path: cart/add-item + methods: [GET] + defaults: + _controller: sylius.controller.order_item::addAction + _sylius: + template: $template + factory: + method: createForProductWithCustomerOption + arguments: [expr:notFoundOnNull(service('sylius.repository.product').find($productId))] + form: + type: Sylius\Bundle\CoreBundle\Form\Type\Order\AddToCartType + options: + product: expr:notFoundOnNull(service('sylius.repository.product').find($productId)) + redirect: + route: sylius_shop_cart_summary + parameters: {} ``` * Copy the template overrides from the plugin directory From 57e823673e1ca79dba8c67ed9c4c227228c2f9ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20Hochd=C3=B6rfer?= Date: Wed, 3 Jan 2024 14:01:05 +0100 Subject: [PATCH 3/8] Use constructor property promotion --- src/Factory/CartItemFactory.php | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/src/Factory/CartItemFactory.php b/src/Factory/CartItemFactory.php index cb2eaa2a..9296860a 100644 --- a/src/Factory/CartItemFactory.php +++ b/src/Factory/CartItemFactory.php @@ -27,23 +27,15 @@ class CartItemFactory implements CartItemFactoryInterface { private CartItemFactoryInterface $decoratedFactory; - private ProductVariantResolverInterface $variantResolver; - private RequestStack $requestStack; - private OrderItemOptionFactoryInterface $orderItemOptionFactory; - private CustomerOptionRepositoryInterface $customerOptionRepository; public function __construct( FactoryInterface $decoratedFactory, - ProductVariantResolverInterface $variantResolver, - RequestStack $requestStack, - OrderItemOptionFactoryInterface $orderItemOptionFactory, - CustomerOptionRepositoryInterface $customerOptionRepository + private ProductVariantResolverInterface $variantResolver, + private RequestStack $requestStack, + private OrderItemOptionFactoryInterface $orderItemOptionFactory, + private CustomerOptionRepositoryInterface $customerOptionRepository ) { $this->decoratedFactory = new \Sylius\Component\Core\Factory\CartItemFactory($decoratedFactory, $variantResolver); - $this->variantResolver = $variantResolver; - $this->requestStack = $requestStack; - $this->orderItemOptionFactory = $orderItemOptionFactory; - $this->customerOptionRepository = $customerOptionRepository; } public function createForProduct(ProductInterface $product): OrderItemInterface From ae7e804ffbaa58aadc467eed86d98f114691beb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20Hochd=C3=B6rfer?= Date: Wed, 3 Jan 2024 14:01:31 +0100 Subject: [PATCH 4/8] Rename service to match naming schema --- src/Resources/config/app/services/factory.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Resources/config/app/services/factory.xml b/src/Resources/config/app/services/factory.xml index dc98e01b..b7ee8280 100644 --- a/src/Resources/config/app/services/factory.xml +++ b/src/Resources/config/app/services/factory.xml @@ -57,9 +57,9 @@ From 65a276620d8a6951bd565f51a0da4366116e67d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20Hochd=C3=B6rfer?= Date: Wed, 3 Jan 2024 14:05:05 +0100 Subject: [PATCH 5/8] Fix code style --- src/Factory/CartItemFactory.php | 26 ++++++++----------- .../OrderItemCustomerOptionCapableTrait.php | 1 - 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/src/Factory/CartItemFactory.php b/src/Factory/CartItemFactory.php index 9296860a..f0bfbdd3 100644 --- a/src/Factory/CartItemFactory.php +++ b/src/Factory/CartItemFactory.php @@ -33,7 +33,7 @@ public function __construct( private ProductVariantResolverInterface $variantResolver, private RequestStack $requestStack, private OrderItemOptionFactoryInterface $orderItemOptionFactory, - private CustomerOptionRepositoryInterface $customerOptionRepository + private CustomerOptionRepositoryInterface $customerOptionRepository, ) { $this->decoratedFactory = new \Sylius\Component\Core\Factory\CartItemFactory($decoratedFactory, $variantResolver); } @@ -55,7 +55,7 @@ public function createNew() public function createForProductWithCustomerOption(ProductInterface $product): OrderItemInterface { - /** @var OrderItemInterface $cartItem */ + /** @var OrderItemInterface $cartItem */ $cartItem = $this->createNew(); $cartItem->setVariant($this->variantResolver->getVariant($product)); @@ -84,7 +84,7 @@ public function createForProductWithCustomerOption(ProductInterface $product): O $salesOrderConfiguration = $this->orderItemOptionFactory->createNewFromStrings( $cartItem, $customerOptionCode, - $value + $value, ); $salesOrderConfigurations[] = $salesOrderConfiguration; @@ -98,10 +98,6 @@ public function createForProductWithCustomerOption(ProductInterface $product): O /** * Gets the customer options from the request - * - * @param Request $request - * - * @return array */ public function getCustomerOptionsFromRequest(Request $request): array { @@ -120,20 +116,20 @@ public function getCustomerOptionsFromRequest(Request $request): array switch ($customerOption->getType()) { case CustomerOptionTypeEnum::DATE: - $day = $value['day']; - $month = $value['month']; - $year = $value['year']; + $day = $value['day']; + $month = $value['month']; + $year = $value['year']; $addToCart['customer_options'][$code] = sprintf('%d-%d-%d', $year, $month, $day); break; case CustomerOptionTypeEnum::DATETIME: - $date = $value['date']; - $time = $value['time']; - $day = $date['day']; + $date = $value['date']; + $time = $value['time']; + $day = $date['day']; $month = $date['month']; - $year = $date['year']; + $year = $date['year']; - $hour = $time['hour'] ?? 0; + $hour = $time['hour'] ?? 0; $minute = $time['minute'] ?? 0; $addToCart['customer_options'][$code] = sprintf('%d-%d-%d %d:%d', $year, $month, $day, $hour, $minute); diff --git a/src/Traits/OrderItemCustomerOptionCapableTrait.php b/src/Traits/OrderItemCustomerOptionCapableTrait.php index 1d28b036..321720e8 100644 --- a/src/Traits/OrderItemCustomerOptionCapableTrait.php +++ b/src/Traits/OrderItemCustomerOptionCapableTrait.php @@ -6,7 +6,6 @@ use Brille24\SyliusCustomerOptionsPlugin\Entity\CustomerOptions\CustomerOptionInterface; use Brille24\SyliusCustomerOptionsPlugin\Entity\OrderItemOptionInterface; -use Brille24\SyliusCustomerOptionsPlugin\Entity\ProductInterface; use Brille24\SyliusCustomerOptionsPlugin\Enumerations\CustomerOptionTypeEnum; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; From e579bdfe809f78ec6d0a72046e6e109b03703f57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20Hochd=C3=B6rfer?= Date: Fri, 5 Jan 2024 11:42:24 +0100 Subject: [PATCH 6/8] Add tests for CartItemFactory --- .../EventListener/AddToCartListenerTest.php | 175 ------------------ tests/PHPUnit/Factory/CartItemFactoryTest.php | 124 +++++++++++++ 2 files changed, 124 insertions(+), 175 deletions(-) delete mode 100644 tests/PHPUnit/EventListener/AddToCartListenerTest.php create mode 100644 tests/PHPUnit/Factory/CartItemFactoryTest.php diff --git a/tests/PHPUnit/EventListener/AddToCartListenerTest.php b/tests/PHPUnit/EventListener/AddToCartListenerTest.php deleted file mode 100644 index fa75bdcc..00000000 --- a/tests/PHPUnit/EventListener/AddToCartListenerTest.php +++ /dev/null @@ -1,175 +0,0 @@ -channel = self::createMock(ChannelInterface::class); - } - - // - public function setUp(): void - { - // Aliasing variables for use in testing - $entitiesPersisted = &$this->entitiesPersisted; - - $requestStack = self::createMock(RequestStack::class); - $requestStack->method('getCurrentRequest')->willReturnCallback(fn () => $this->request); - - $entityManager = self::createMock(EntityManagerInterface::class); - $entityManager->method('persist')->willReturnCallback(function ($entity) use (&$entitiesPersisted) { - if (!array_key_exists($entity::class, $entitiesPersisted)) { - $entitiesPersisted[$entity::class] = 1; - } - ++$entitiesPersisted[$entity::class]; - }); - - $orderItemOptionFactory = self::createMock(OrderItemOptionFactoryInterface::class); - $orderItemOptionFactory->method('createNewFromStrings')->willReturnCallback( - function ($orderItem, $customerOptionCode, $value) { - if (!array_key_exists($customerOptionCode, $this->customerOptions)) { - throw new \Exception('Not found'); - } - - $orderItemOption = new OrderItemOption($this->channel, $this->customerOptions[$customerOptionCode], $value); - $orderItemOption->setOrderItem($orderItem); - - return $orderItemOption; - }, - ); - - $orderProcessor = self::createMock(OrderProcessorInterface::class); - - $this->customerOptionRepository = self::createMock(CustomerOptionRepositoryInterface::class); - - $this->addToCartListener = new AddToCartListener( - $requestStack, - $entityManager, - $orderItemOptionFactory, - $orderProcessor, - $this->customerOptionRepository, - ); - } - - private function createEvent(bool $hasOrder): ResourceControllerEvent - { - $product = self::createConfiguredMock(ProductInterface::class, []); - - $channel = self::createMock(ChannelInterface::class); - $order = self::createConfiguredMock(OrderInterface::class, ['getChannel' => $channel]); - $orderItem = self::createMock(OrderItemInterface::class); - $orderItem->method('getOrder')->willReturn($hasOrder ? $order : null); - $orderItem->method('getProduct')->willReturn($product); - - $event = self::createMock(ResourceControllerEvent::class); - $event->method('getSubject')->willReturn($orderItem); - - return $event; - } - - private function createRequest(array $customerOptions): Request - { - $request = new Request(); - - $request->request = self::createMock(ParameterBag::class); - $request->request->method('get')->willReturnCallback(function ($key) use ($customerOptions) { - self::assertEquals('sylius_add_to_cart', $key); - - return $customerOptions; - }); - - return $request; - } - - // - - public function testWithIncreasedProduct(): void - { - // SETUP - $event = $this->createEvent(false); - - // EXECUTE - $this->addToCartListener->addItemToCart($event); - - // ASSERT - self::assertCount(0, $this->entitiesPersisted); - } - - public function testWithEmptyCustomerOptions(): void - { - // SETUP - $event = $this->createEvent(true); - $this->request = $this->createRequest([]); - - // EXECUTE - $this->addToCartListener->addItemToCart($event); - - // ASSERT - self::assertCount(1, $this->entitiesPersisted); - } - - public function testInvalidCustomerOptionCode(): void - { - // SETUP - $this->customerOptionRepository->method('findOneByCode')->with('customerOptionCode')->willReturn(self::createMock(CustomerOptionInterface::class)); - $event = $this->createEvent(true); - $this->request = $this->createRequest(['customer_options' => ['customerOptionCode' => 'value']]); - - self::expectException(\Exception::class); - self::expectExceptionMessage('Not found'); - - // EXECUTE - $this->addToCartListener->addItemToCart($event); - } - - public function testValidCustomerOptionCode(): void - { - // SETUP - $this->customerOptions['customerOptionCode'] = self::createMock(CustomerOptionInterface::class); - $this->customerOptionRepository->method('findOneByCode')->with('customerOptionCode')->willReturn($this->customerOptions['customerOptionCode']); - - $event = $this->createEvent(true); - $this->request = $this->createRequest(['customer_options' => ['customerOptionCode' => 'value']]); - - // EXECUTE - $this->addToCartListener->addItemToCart($event); - - // ASSERT - self::assertCount(2, $this->entitiesPersisted); - } -} diff --git a/tests/PHPUnit/Factory/CartItemFactoryTest.php b/tests/PHPUnit/Factory/CartItemFactoryTest.php new file mode 100644 index 00000000..3000bf64 --- /dev/null +++ b/tests/PHPUnit/Factory/CartItemFactoryTest.php @@ -0,0 +1,124 @@ +orderItem = new class extends OrderItem implements OrderItemInterface { + use OrderItemCustomerOptionCapableTrait; + }; + + $decoratedFactory = $this->createMock(CartItemFactoryInterface::class); + $decoratedFactory->method('createNew')->willReturn($this->orderItem); + + $variantResolver = $this->createMock(ProductVariantResolverInterface::class); + $this->orderItemOptionFactory = $this->createMock(OrderItemOptionFactoryInterface::class); + $this->customerOptionRepository = $this->createMock(CustomerOptionRepositoryInterface::class); + + $this->requestStack = $this->createMock(RequestStack::class); + $this->cartItemFactory = new CartItemFactory( + $decoratedFactory, + $variantResolver, + $this->requestStack, + $this->orderItemOptionFactory, + $this->customerOptionRepository + ); + } + + /** + * @test + */ + public function createForProductWithCustomerOptionWithoutRequest(): void + { + $this->requestStack->method('getCurrentRequest')->willReturn(null); + + $product = $this->createMock(ProductInterface::class); + $cartItem = $this->cartItemFactory->createForProductWithCustomerOption($product); + + $this->assertInstanceOf(OrderItemInterface::class, $cartItem); + $this->assertCount(0, $cartItem->getCustomerOptionConfiguration()); + } + + /** + * @test + */ + public function createForProductWithCustomerOptionFromRequestWithoutCustomerOptions(): void + { + $request = new Request(); + $this->requestStack->method('getCurrentRequest')->willReturn($request); + + $product = $this->createMock(ProductInterface::class); + $cartItem = $this->cartItemFactory->createForProductWithCustomerOption($product); + + $this->assertInstanceOf(OrderItemInterface::class, $cartItem); + $this->assertCount(0, $cartItem->getCustomerOptionConfiguration()); + } + + /** + * @test + */ + public function createForProductWithCustomerOptionFromRequestWithCustomerOptions(): void + { + $customerOption = new CustomerOption(); + $customerOption->setCode('name'); + $customerOption->setCurrentLocale('en'); + + $request = new Request([], ['sylius_add_to_cart' => ['customer_options' => ['name' => 'My name']]]); + $this->requestStack->method('getCurrentRequest')->willReturn($request); + + $this->customerOptionRepository->method('findOneByCode')->with('name')->willReturn($customerOption); + + $this->orderItemOptionFactory->method('createNewFromStrings')->willReturnCallback( + function ($orderItem, $customerOptionCode, $value) use ($customerOption) { + $orderItemOption = new OrderItemOption(); + $orderItemOption->setOrderItem($orderItem); + $orderItemOption->setCustomerOption($customerOption); + $orderItemOption->setCustomerOptionValue($value); + + return $orderItemOption; + }, + ); + + $product = $this->createMock(ProductInterface::class); + $cartItem = $this->cartItemFactory->createForProductWithCustomerOption($product); + + $this->assertInstanceOf(OrderItemInterface::class, $cartItem); + $this->assertCount(1, $cartItem->getCustomerOptionConfiguration()); + } +} From 934783cc4594e32b916792d35b52623988217a2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20Hochd=C3=B6rfer?= Date: Fri, 5 Jan 2024 11:42:55 +0100 Subject: [PATCH 7/8] Make CartItemFactory helper method private --- src/Factory/CartItemFactory.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Factory/CartItemFactory.php b/src/Factory/CartItemFactory.php index f0bfbdd3..cf6ccc9c 100644 --- a/src/Factory/CartItemFactory.php +++ b/src/Factory/CartItemFactory.php @@ -99,7 +99,7 @@ public function createForProductWithCustomerOption(ProductInterface $product): O /** * Gets the customer options from the request */ - public function getCustomerOptionsFromRequest(Request $request): array + private function getCustomerOptionsFromRequest(Request $request): array { /** @var array $addToCart */ $addToCart = $request->request->all('sylius_add_to_cart'); From ff96a3ebe843bc41009f119506350bfe230a74cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20Hochd=C3=B6rfer?= Date: Fri, 5 Jan 2024 11:43:25 +0100 Subject: [PATCH 8/8] Optimize XML service config --- src/Resources/config/app/services/factory.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Resources/config/app/services/factory.xml b/src/Resources/config/app/services/factory.xml index b7ee8280..1229d5c6 100644 --- a/src/Resources/config/app/services/factory.xml +++ b/src/Resources/config/app/services/factory.xml @@ -62,7 +62,7 @@ decoration-priority="255" public="false" > - +