/** * @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(); }
/** * @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); }
/** * {@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); }
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); }
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); }