function it_returns_empty_array_if_zone_matcher_could_not_match_any_zone(AddressInterface $address, OrderInterface $order, ShipmentInterface $shipment, ZoneMatcherInterface $zoneMatcher)
 {
     $shipment->getOrder()->willReturn($order);
     $order->getShippingAddress()->willReturn($address);
     $zoneMatcher->matchAll($address)->willReturn([]);
     $this->getSupportedMethods($shipment)->shouldReturn([]);
 }
Exemplo n.º 2
0
 /**
  * @param AddressInterface|null $shippingAddress
  *
  * @return ZoneInterface|null
  */
 private function getTaxZone(AddressInterface $shippingAddress = null)
 {
     $zone = null;
     if (null !== $shippingAddress) {
         $zone = $this->zoneMatcher->match($shippingAddress);
     }
     return $zone ?: $this->defaultTaxZoneProvider->getZone();
 }
Exemplo n.º 3
0
 /**
  * @param OrderInterface $order
  *
  * @return ZoneInterface|null
  */
 private function getTaxZone(OrderInterface $order)
 {
     $shippingAddress = $order->getShippingAddress();
     $zone = null;
     if (null !== $shippingAddress) {
         $zone = $this->zoneMatcher->match($shippingAddress);
     }
     return $zone ?: $this->defaultTaxZoneProvider->getZone($order);
 }
 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]);
 }
 /**
  * @param OrderInterface $order
  *
  * @return array
  */
 private function getZonesIdsForAddress(OrderInterface $order)
 {
     $matchedZones = $this->zoneMatcher->matchAll($order->getShippingAddress());
     if (empty($matchedZones)) {
         return [];
     }
     $zones = [];
     foreach ($matchedZones as $zone) {
         $zones[] = $zone->getId();
     }
     return $zones;
 }
 /**
  * {@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());
 }
 /**
  * {@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;
 }
Exemplo n.º 8
0
 function it_does_not_process_taxes_if_there_is_no_tax_zone(ZoneProviderInterface $defaultTaxZoneProvider, ZoneMatcherInterface $zoneMatcher, PrioritizedServiceRegistryInterface $strategyRegistry, OrderInterface $order, OrderItemInterface $orderItem, AddressInterface $address)
 {
     $order->getItems()->willReturn([$orderItem]);
     $order->isEmpty()->willReturn(false);
     $order->removeAdjustments(AdjustmentInterface::TAX_ADJUSTMENT)->shouldBeCalled();
     $orderItem->removeAdjustmentsRecursively(AdjustmentInterface::TAX_ADJUSTMENT)->shouldBeCalled();
     $order->getShippingAddress()->willReturn($address);
     $zoneMatcher->match($address)->willReturn(null);
     $defaultTaxZoneProvider->getZone($order)->willReturn(null);
     $strategyRegistry->all()->shouldNotBeCalled();
     $this->process($order);
 }
Exemplo n.º 9
0
 /**
  * {@inheritdoc}
  */
 public function applyTaxes(OrderInterface $order)
 {
     // Remove all tax adjustments, we recalculate everything from scratch.
     $order->removeAdjustments(AdjustmentInterface::TAX_ADJUSTMENT);
     if ($order->getItems()->isEmpty()) {
         return;
     }
     $zone = null;
     if (null !== $order->getShippingAddress()) {
         // Match the tax zone.
         $zone = $this->zoneMatcher->match($order->getShippingAddress());
     }
     if ($this->settings->has('default_tax_zone')) {
         // If address does not match any zone, use the default one.
         $zone = $zone ?: $this->settings->get('default_tax_zone');
     }
     if (null === $zone) {
         return;
     }
     $taxes = $this->processTaxes($order, $zone);
     $this->addAdjustments($taxes, $order);
 }
Exemplo n.º 10
0
 function it_does_not_process_taxes_if_there_is_no_tax_zone(ZoneProviderInterface $defaultTaxZoneProvider, ZoneMatcherInterface $zoneMatcher, AddressInterface $address, \Iterator $itemsIterator, Collection $items, OrderInterface $order, OrderItemInterface $orderItem, PrioritizedServiceRegistryInterface $strategyRegistry)
 {
     $order->removeAdjustments(AdjustmentInterface::TAX_ADJUSTMENT)->shouldBeCalled();
     $order->getItems()->willReturn($items);
     $order->isEmpty()->willReturn(false);
     $items->count()->willReturn(1);
     $items->getIterator()->willReturn($itemsIterator);
     $itemsIterator->rewind()->shouldBeCalled();
     $itemsIterator->valid()->willReturn(true, false)->shouldBeCalled();
     $itemsIterator->current()->willReturn($orderItem);
     $itemsIterator->next()->shouldBeCalled();
     $orderItem->removeAdjustmentsRecursively(AdjustmentInterface::TAX_ADJUSTMENT)->shouldBeCalled();
     $order->getShippingAddress()->willReturn($address);
     $zoneMatcher->match($address)->willReturn(null);
     $defaultTaxZoneProvider->getZone($order)->willReturn(null);
     $strategyRegistry->all()->shouldNotBeCalled();
     $this->process($order);
 }