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]); }
function it_returns_shipping_methods_matched_for_shipment_order_shipping_address_and_order_channel(AddressInterface $address, ChannelInterface $channel, OrderInterface $order, ShipmentInterface $shipment, ShippingMethodInterface $firstShippingMethod, ShippingMethodInterface $secondShippingMethod, ShippingMethodRepositoryInterface $shippingMethodRepository, ZoneInterface $firstZone, ZoneInterface $secondZone, ZoneMatcherInterface $zoneMatcher) { $shipment->getOrder()->willReturn($order); $order->getShippingAddress()->willReturn($address); $order->getChannel()->willReturn($channel); $zoneMatcher->matchAll($address)->willReturn([$firstZone, $secondZone]); $shippingMethodRepository->findEnabledForZonesAndChannel([$firstZone, $secondZone], $channel)->willReturn([$firstShippingMethod, $secondShippingMethod]); $this->getSupportedMethods($shipment)->shouldReturn([$firstShippingMethod, $secondShippingMethod]); }
function it_returns_only_shipping_methods_that_are_eligible(ShippingMethodEligibilityCheckerInterface $eligibilityChecker, AddressInterface $address, ChannelInterface $channel, OrderInterface $order, ShipmentInterface $shipment, ShippingMethodInterface $firstShippingMethod, ShippingMethodInterface $secondShippingMethod, ShippingMethodRepositoryInterface $shippingMethodRepository, ZoneInterface $firstZone, ZoneInterface $secondZone, ZoneMatcherInterface $zoneMatcher) { $shipment->getOrder()->willReturn($order); $order->getShippingAddress()->willReturn($address); $order->getChannel()->willReturn($channel); $zoneMatcher->matchAll($address)->willReturn([$firstZone, $secondZone]); $eligibilityChecker->isEligible($shipment, $firstShippingMethod)->willReturn(false); $eligibilityChecker->isEligible($shipment, $secondShippingMethod)->willReturn(true); $shippingMethodRepository->findEnabledForZonesAndChannel([$firstZone, $secondZone], $channel)->willReturn([$firstShippingMethod, $secondShippingMethod]); $this->getSupportedMethods($shipment)->shouldReturn([$secondShippingMethod]); }
/** * {@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]; }
/** * {@inheritdoc} */ public function getSupportedMethods(ShippingSubjectInterface $subject) { /** @var ShipmentInterface $subject */ Assert::true($this->supports($subject)); /** @var OrderInterface $order */ $order = $subject->getOrder(); $zones = $this->zoneMatcher->matchAll($order->getShippingAddress()); if (empty($zones)) { return []; } return $this->shippingMethodRepository->findEnabledForZonesAndChannel($zones, $order->getChannel()); }
/** * @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); }
/** * {@inheritdoc} */ public function getSupportedMethods(ShippingSubjectInterface $subject) { /** @var ShipmentInterface $subject */ Assert::true($this->supports($subject)); /** @var OrderInterface $order */ $order = $subject->getOrder(); $zones = $this->zoneMatcher->matchAll($order->getShippingAddress()); if (empty($zones)) { return []; } $methods = []; $shippingMethods = $this->shippingMethodRepository->findEnabledForZonesAndChannel($zones, $order->getChannel()); foreach ($shippingMethods as $shippingMethod) { if ($this->eligibilityChecker->isEligible($subject, $shippingMethod)) { $methods[] = $shippingMethod; } } return $methods; }
/** * @param ShippingMethodInterface $shippingMethod */ private function saveShippingMethod(ShippingMethodInterface $shippingMethod) { $this->shippingMethodRepository->add($shippingMethod); $this->sharedStorage->set('shipping_method', $shippingMethod); }