diff --git a/src/Sylius/Bundle/CoreBundle/Fixture/OrderFixture.php b/src/Sylius/Bundle/CoreBundle/Fixture/OrderFixture.php index 8d513477456..bb009a453ea 100644 --- a/src/Sylius/Bundle/CoreBundle/Fixture/OrderFixture.php +++ b/src/Sylius/Bundle/CoreBundle/Fixture/OrderFixture.php @@ -179,9 +179,6 @@ private function generateItems(OrderInterface $order): void $products = $this->productRepository->findAll(); $generatedItems = []; - $shippingMethods = $this->shippingMethodRepository->findEnabledForChannel($order->getChannel()); - $shippingMethodsAvailable = count($shippingMethods) > 0; - for ($i = 0; $i < $numberOfItems; ++$i) { /** @var ProductInterface $product */ $product = $this->faker->randomElement($products); @@ -197,7 +194,6 @@ private function generateItems(OrderInterface $order): void /** @var OrderItemInterface $item */ $item = $generatedItems[$variant->getCode()]; $this->orderItemQuantityModifier->modify($item, $item->getQuantity() + random_int(1, 5)); - $variant->setShippingRequired($shippingMethodsAvailable); continue; } @@ -238,10 +234,17 @@ private function selectShipping(OrderInterface $order): void return; } - $shippingMethod = $this - ->faker - ->randomElement($this->shippingMethodRepository->findEnabledForChannel($order->getChannel())) - ; + $channel = $order->getChannel(); + $shippingMethods = $this->shippingMethodRepository->findEnabledForChannel($channel); + + if (count($shippingMethods) === 0) { + throw new \InvalidArgumentException(sprintf( + 'You have no shipping method available for the channel with code "%s", but they are required to proceed an order', + $channel->getCode() + )); + } + + $shippingMethod = $this->faker->randomElement($shippingMethods); /** @var ChannelInterface $channel */ $channel = $order->getChannel();