/** * @param OrderItemUnitInterface $unit * @param PromotionInterface $promotion */ private function removeUnitOrderPromotionAdjustmentsByOrigin(OrderItemUnitInterface $unit, PromotionInterface $promotion) { foreach ($unit->getAdjustments(AdjustmentInterface::ORDER_PROMOTION_ADJUSTMENT) as $adjustment) { if ($promotion->getCode() === $adjustment->getOriginCode()) { $unit->removeAdjustment($adjustment); } } }
/** * @param OrderItemUnitInterface $unit * @param PromotionInterface $promotion */ protected function removeUnitOrderItemAdjustments(OrderItemUnitInterface $unit, PromotionInterface $promotion) { foreach ($unit->getAdjustments(AdjustmentInterface::ORDER_UNIT_PROMOTION_ADJUSTMENT) as $adjustment) { if ($promotion === $this->originator->getOrigin($adjustment)) { $unit->removeAdjustment($adjustment); } } }
function it_reverts_order_units_order_promotion_adjustments(AdjustmentInterface $firstAdjustment, AdjustmentInterface $secondAdjustment, OrderInterface $order, OrderItemInterface $item, OrderItemUnitInterface $unit, OriginatorInterface $originator, PromotionInterface $otherPromotion, PromotionInterface $promotion) { $order->countItems()->willReturn(1); $order->getItems()->willReturn(new \ArrayIterator([$item->getWrappedObject()])); $item->getUnits()->willReturn(new \ArrayIterator([$unit->getWrappedObject()])); $unit->getAdjustments(AdjustmentInterface::ORDER_PROMOTION_ADJUSTMENT)->willReturn(new \ArrayIterator([$firstAdjustment->getWrappedObject(), $secondAdjustment->getWrappedObject()])); $originator->getOrigin($firstAdjustment)->willReturn($promotion); $originator->getOrigin($secondAdjustment)->willReturn($otherPromotion); $unit->removeAdjustment($firstAdjustment)->shouldBeCalled(); $unit->removeAdjustment($secondAdjustment)->shouldNotBeCalled(); $this->revert($order, [], $promotion); }
function it_reverts_order_units_order_promotion_adjustments(AdjustmentInterface $firstAdjustment, AdjustmentInterface $secondAdjustment, OrderInterface $order, OrderItemInterface $item, OrderItemUnitInterface $unit, PromotionInterface $promotion) { $order->countItems()->willReturn(1); $order->getItems()->willReturn([$item]); $item->getUnits()->willReturn([$unit]); $unit->getAdjustments(AdjustmentInterface::ORDER_PROMOTION_ADJUSTMENT)->willReturn([$firstAdjustment, $secondAdjustment]); $promotion->getCode()->willReturn('PROMOTION'); $firstAdjustment->getOriginCode()->willReturn('PROMOTION'); $secondAdjustment->getOriginCode()->willReturn('OTHER_PROMOTION'); $unit->removeAdjustment($firstAdjustment)->shouldBeCalled(); $unit->removeAdjustment($secondAdjustment)->shouldNotBeCalled(); $this->revert($order, [], $promotion); }
function it_reverts_proper_promotion_adjustment_from_all_units($originator, AdjustmentInterface $promotionAdjustment1, AdjustmentInterface $promotionAdjustment2, Collection $items, Collection $units, Collection $adjustments, OrderInterface $order, OrderItemInterface $orderItem, OrderItemUnitInterface $unit, PromotionInterface $promotion, PromotionInterface $someOtherPromotion) { $order->getItems()->willReturn($items); $items->getIterator()->willReturn(new \ArrayIterator([$orderItem->getWrappedObject()])); $orderItem->getUnits()->willReturn($units); $units->getIterator()->willReturn(new \ArrayIterator([$unit->getWrappedObject()])); $unit->getAdjustments(AdjustmentInterface::ORDER_UNIT_PROMOTION_ADJUSTMENT)->willReturn($adjustments); $adjustments->getIterator()->willReturn(new \ArrayIterator([$promotionAdjustment1->getWrappedObject(), $promotionAdjustment2->getWrappedObject()])); $originator->getOrigin($promotionAdjustment1)->willReturn($promotion); $unit->removeAdjustment($promotionAdjustment1)->shouldBeCalled(); $originator->getOrigin($promotionAdjustment2)->willReturn($someOtherPromotion); $unit->removeAdjustment($promotionAdjustment2)->shouldNotBeCalled(); $this->revert($order, ['percentage' => 0.2], $promotion); }
function it_revert_proper_promotion_adjustment_from_all_units(AdjustmentInterface $promotionAdjustment1, AdjustmentInterface $promotionAdjustment2, Collection $items, Collection $units, Collection $adjustments, OrderInterface $order, OrderItemInterface $orderItem, OrderItemUnitInterface $unit, PromotionInterface $promotion) { $order->getItems()->willReturn($items); $items->getIterator()->willReturn(new \ArrayIterator([$orderItem->getWrappedObject()])); $orderItem->getUnits()->willReturn($units); $units->getIterator()->willReturn(new \ArrayIterator([$unit->getWrappedObject()])); $unit->getAdjustments(AdjustmentInterface::ORDER_UNIT_PROMOTION_ADJUSTMENT)->willReturn($adjustments); $adjustments->getIterator()->willReturn(new \ArrayIterator([$promotionAdjustment1->getWrappedObject(), $promotionAdjustment2->getWrappedObject()])); $promotion->getCode()->willReturn('PROMOTION'); $promotionAdjustment1->getOriginCode()->willReturn('PROMOTION'); $unit->removeAdjustment($promotionAdjustment1)->shouldBeCalled(); $promotionAdjustment2->getOriginCode()->willReturn('OTHER_PROMOTION'); $unit->removeAdjustment($promotionAdjustment2)->shouldNotBeCalled(); $this->revert($order, ['amount' => 1000], $promotion); }
function it_reverts_a_proper_promotion_adjustment_from_all_units(AdjustmentInterface $promotionAdjustment1, AdjustmentInterface $promotionAdjustment2, ChannelInterface $channel, OrderInterface $order, OrderItemInterface $orderItem, OrderItemUnitInterface $unit, PromotionInterface $promotion) { $order->getChannel()->willReturn($channel); $channel->getCode()->willReturn('WEB_US'); $order->getItems()->willReturn(new ArrayCollection([$orderItem->getWrappedObject()])); $orderItem->getUnits()->willReturn(new ArrayCollection([$unit->getWrappedObject()])); $unit->getAdjustments(AdjustmentInterface::ORDER_UNIT_PROMOTION_ADJUSTMENT)->willReturn(new ArrayCollection([$promotionAdjustment1->getWrappedObject(), $promotionAdjustment2->getWrappedObject()])); $promotion->getCode()->willReturn('PROMOTION'); $promotionAdjustment1->getOriginCode()->willReturn('PROMOTION'); $unit->removeAdjustment($promotionAdjustment1)->shouldBeCalled(); $promotionAdjustment2->getOriginCode()->willReturn('OTHER_PROMOTION'); $unit->removeAdjustment($promotionAdjustment2)->shouldNotBeCalled(); $this->revert($order, ['WEB_US' => ['amount' => 1000]], $promotion); }