/**
  * {@inheritdoc}
  */
 public function getDefaultShippingMethod(ShipmentInterface $shipment)
 {
     /** @var CoreShipmentInterface $shipment */
     Assert::isInstanceOf($shipment, CoreShipmentInterface::class);
     /** @var ChannelInterface $channel */
     $channel = $shipment->getOrder()->getChannel();
     $shippingMethods = $this->shippingMethodRepository->findEnabledForChannel($channel);
     if (empty($shippingMethods)) {
         throw new UnresolvedDefaultShippingMethodException();
     }
     return $shippingMethods[0];
 }
 function it_throws_an_exception_if_there_is_no_enabled_shipping_methods(ShippingMethodRepositoryInterface $shippingMethodRepository, ShipmentInterface $shipment, ChannelInterface $channel, OrderInterface $order)
 {
     $shipment->getOrder()->willReturn($order);
     $order->getChannel()->willReturn($channel);
     $shippingMethodRepository->findEnabledForChannel($channel)->willReturn([]);
     $this->shouldThrow(UnresolvedDefaultShippingMethodException::class)->during('getDefaultShippingMethod', [$shipment]);
 }
Пример #3
0
 /**
  * @param OrderInterface $order
  */
 private function selectShipping(OrderInterface $order)
 {
     $shippingMethod = $this->faker->randomElement($this->shippingMethodRepository->findEnabledForChannel($order->getChannel()));
     Assert::notNull($shippingMethod, 'Shipping method should not be null.');
     foreach ($order->getShipments() as $shipment) {
         $shipment->setMethod($shippingMethod);
     }
     $this->applyCheckoutStateTransition($order, OrderCheckoutTransitions::TRANSITION_SELECT_SHIPPING);
 }