function it_returns_all_methods_eligible_for_given_subject(ObjectRepository $methodRepository, ShippingMethodEligibilityCheckerInterface $eligibilityChecker, ShippingSubjectInterface $subject, ShippingMethodInterface $method1, ShippingMethodInterface $method2, ShippingMethodInterface $method3)
 {
     $methods = [$method1, $method2, $method3];
     $methodRepository->findBy(['enabled' => true])->shouldBeCalled()->willReturn($methods);
     $eligibilityChecker->isEligible($subject, $method1)->shouldBeCalled()->willReturn(true);
     $eligibilityChecker->isEligible($subject, $method2)->shouldBeCalled()->willReturn(true);
     $eligibilityChecker->isEligible($subject, $method3)->shouldBeCalled()->willReturn(false);
     $this->getSupportedMethods($subject)->shouldReturn([$method1, $method2]);
 }
Exemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public function getSupportedMethods(ShippingSubjectInterface $subject)
 {
     $methods = [];
     foreach ($this->shippingMethodRepository->findBy(['enabled' => true]) as $shippingMethod) {
         if ($this->eligibilityChecker->isEligible($subject, $shippingMethod)) {
             $methods[] = $shippingMethod;
         }
     }
     return $methods;
 }
Exemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 public function getSupportedMethods(ShippingSubjectInterface $subject, array $criteria = [])
 {
     $methods = [];
     foreach ($this->getMethods($criteria) as $method) {
         if ($this->eligibilityChecker->isEligible($subject, $method)) {
             $methods[] = $method;
         }
     }
     return $methods;
 }
 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 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;
 }