Skip to content

Commit

Permalink
Merge pull request Sylius#9308 from Zales0123/inject-adjustments-to-c…
Browse files Browse the repository at this point in the history
…lear

[Adjustment] Inject adjustment types that shall be cleared
  • Loading branch information
pamil committed Apr 10, 2018
2 parents da9ca37 + e7f020e commit 5ae406a
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 9 deletions.
Expand Up @@ -14,6 +14,14 @@
<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<service id="sylius.order_processing.order_adjustments_clearer" class="Sylius\Component\Core\OrderProcessing\OrderAdjustmentsClearer">
<argument type="collection">
<argument type="constant">Sylius\Component\Core\Model\AdjustmentInterface::ORDER_ITEM_PROMOTION_ADJUSTMENT</argument>
<argument type="constant">Sylius\Component\Core\Model\AdjustmentInterface::ORDER_PROMOTION_ADJUSTMENT</argument>
<argument type="constant">Sylius\Component\Core\Model\AdjustmentInterface::ORDER_SHIPPING_PROMOTION_ADJUSTMENT</argument>
<argument type="constant">Sylius\Component\Core\Model\AdjustmentInterface::ORDER_UNIT_PROMOTION_ADJUSTMENT</argument>
<argument type="constant">Sylius\Component\Core\Model\AdjustmentInterface::SHIPPING_ADJUSTMENT</argument>
<argument type="constant">Sylius\Component\Core\Model\AdjustmentInterface::TAX_ADJUSTMENT</argument>
</argument>
<tag name="sylius.order_processor" priority="60"/>
</service>

Expand Down
Expand Up @@ -22,20 +22,34 @@ final class OrderAdjustmentsClearer implements OrderProcessorInterface
/**
* @var array
*/
private static $adjustmentsToRemove = [
AdjustmentInterface::ORDER_ITEM_PROMOTION_ADJUSTMENT,
AdjustmentInterface::ORDER_PROMOTION_ADJUSTMENT,
AdjustmentInterface::ORDER_SHIPPING_PROMOTION_ADJUSTMENT,
AdjustmentInterface::ORDER_UNIT_PROMOTION_ADJUSTMENT,
AdjustmentInterface::TAX_ADJUSTMENT,
];
private $adjustmentsToRemove;

public function __construct(array $adjustmentsToRemove = [])
{
if (0 === func_num_args()) {
@trigger_error(
'Not passing adjustments types explicitly is deprecated since 1.2 and will be prohibited in 2.0',
E_USER_DEPRECATED
);

$adjustmentsToRemove = [
AdjustmentInterface::ORDER_ITEM_PROMOTION_ADJUSTMENT,
AdjustmentInterface::ORDER_PROMOTION_ADJUSTMENT,
AdjustmentInterface::ORDER_SHIPPING_PROMOTION_ADJUSTMENT,
AdjustmentInterface::ORDER_UNIT_PROMOTION_ADJUSTMENT,
AdjustmentInterface::TAX_ADJUSTMENT,
];
}

$this->adjustmentsToRemove = $adjustmentsToRemove;
}

/**
* {@inheritdoc}
*/
public function process(OrderInterface $order): void
{
foreach (self::$adjustmentsToRemove as $type) {
foreach ($this->adjustmentsToRemove as $type) {
$order->removeAdjustmentsRecursively($type);
}
}
Expand Down
Expand Up @@ -25,7 +25,7 @@ function it_is_an_order_processor(): void
$this->shouldImplement(OrderProcessorInterface::class);
}

function it_removes_adjustments_from_order_recursively(OrderInterface $order): void
function it_removes_adjustments_with_default_types_from_order_recursively(OrderInterface $order): void
{
$order->removeAdjustmentsRecursively(AdjustmentInterface::ORDER_ITEM_PROMOTION_ADJUSTMENT)->shouldBeCalled();
$order->removeAdjustmentsRecursively(AdjustmentInterface::ORDER_PROMOTION_ADJUSTMENT)->shouldBeCalled();
Expand All @@ -35,4 +35,17 @@ function it_removes_adjustments_from_order_recursively(OrderInterface $order): v

$this->process($order);
}

function it_removes_adjustments_with_specified_types_from_order_recursively(OrderInterface $order): void
{
$this->beConstructedWith([
AdjustmentInterface::ORDER_ITEM_PROMOTION_ADJUSTMENT,
AdjustmentInterface::ORDER_PROMOTION_ADJUSTMENT,
]);

$order->removeAdjustmentsRecursively(AdjustmentInterface::ORDER_ITEM_PROMOTION_ADJUSTMENT)->shouldBeCalled();
$order->removeAdjustmentsRecursively(AdjustmentInterface::ORDER_PROMOTION_ADJUSTMENT)->shouldBeCalled();

$this->process($order);
}
}

0 comments on commit 5ae406a

Please sign in to comment.