Skip to content

Commit

Permalink
[OrderProcessor] Fix clearing tax adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
GSadee committed Jan 14, 2021
1 parent 066364b commit c849cde
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Sylius\Component\Core\Model\AdjustmentInterface;
use Sylius\Component\Core\Model\OrderInterface;
use Sylius\Component\Core\Model\Scope;
use Sylius\Component\Core\Model\ShipmentInterface;
use Sylius\Component\Core\Provider\ZoneProviderInterface;
use Sylius\Component\Core\Taxation\Exception\UnsupportedTaxCalculationStrategyException;
use Sylius\Component\Core\Taxation\Strategy\TaxCalculationStrategyInterface;
Expand Down Expand Up @@ -87,11 +88,17 @@ private function getTaxZone(OrderInterface $order): ?ZoneInterface
return $zone ?: $this->defaultTaxZoneProvider->getZone($order);
}

private function clearTaxes(BaseOrderInterface $order): void
private function clearTaxes(OrderInterface $order): void
{
$order->removeAdjustments(AdjustmentInterface::TAX_ADJUSTMENT);

foreach ($order->getItems() as $item) {
$item->removeAdjustmentsRecursively(AdjustmentInterface::TAX_ADJUSTMENT);
}

/** @var ShipmentInterface $shipment */
foreach ($order->getShipments() as $shipment) {
$shipment->removeAdjustments(AdjustmentInterface::TAX_ADJUSTMENT);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use Sylius\Component\Core\Model\OrderInterface;
use Sylius\Component\Core\Model\OrderItemInterface;
use Sylius\Component\Core\Model\Scope;
use Sylius\Component\Core\Model\ShipmentInterface;
use Sylius\Component\Core\Provider\ZoneProviderInterface;
use Sylius\Component\Core\Taxation\Exception\UnsupportedTaxCalculationStrategyException;
use Sylius\Component\Core\Taxation\Strategy\TaxCalculationStrategyInterface;
Expand All @@ -48,17 +49,20 @@ function it_processes_taxes_using_a_supported_tax_calculation_strategy(
PrioritizedServiceRegistryInterface $strategyRegistry,
OrderInterface $order,
OrderItemInterface $orderItem,
ShipmentInterface $shipment,
AddressInterface $address,
ZoneInterface $zone,
TaxCalculationStrategyInterface $strategyOne,
TaxCalculationStrategyInterface $strategyTwo
): void {
$order->getItems()->willReturn(new ArrayCollection([$orderItem->getWrappedObject()]));
$order->getShipments()->willReturn(new ArrayCollection([$shipment->getWrappedObject()]));
$order->isEmpty()->willReturn(false);
$order->getBillingAddress()->willReturn($address);

$order->removeAdjustments(AdjustmentInterface::TAX_ADJUSTMENT)->shouldBeCalled();
$orderItem->removeAdjustmentsRecursively(AdjustmentInterface::TAX_ADJUSTMENT)->shouldBeCalled();
$shipment->removeAdjustments(AdjustmentInterface::TAX_ADJUSTMENT)->shouldBeCalled();

$strategyRegistry->all()->willReturn([$strategyOne, $strategyTwo]);
$zoneMatcher->match($address, Scope::TAX)->willReturn($zone);
Expand All @@ -82,6 +86,7 @@ function it_throws_an_exception_if_there_are_no_supported_tax_calculation_strate
TaxCalculationStrategyInterface $strategy
): void {
$order->getItems()->willReturn(new ArrayCollection([$orderItem->getWrappedObject()]));
$order->getShipments()->willReturn(new ArrayCollection([]));
$order->isEmpty()->willReturn(false);
$order->getBillingAddress()->willReturn($address);

Expand All @@ -102,6 +107,7 @@ function it_does_not_process_taxes_if_there_is_no_order_item(OrderInterface $ord
{
$order->removeAdjustments(AdjustmentInterface::TAX_ADJUSTMENT)->shouldBeCalled();
$order->getItems()->willReturn(new ArrayCollection([]));
$order->getShipments()->willReturn(new ArrayCollection([]));
$order->isEmpty()->willReturn(true);

$order->getBillingAddress()->shouldNotBeCalled();
Expand All @@ -118,6 +124,7 @@ function it_does_not_process_taxes_if_there_is_no_tax_zone(
AddressInterface $address
): void {
$order->getItems()->willReturn(new ArrayCollection([$orderItem->getWrappedObject()]));
$order->getShipments()->willReturn(new ArrayCollection([]));
$order->isEmpty()->willReturn(false);

$order->removeAdjustments(AdjustmentInterface::TAX_ADJUSTMENT)->shouldBeCalled();
Expand Down

0 comments on commit c849cde

Please sign in to comment.