function it_does_nothing_if_adjustment_amount_would_be_0(ProportionalIntegerDistributorInterface $distributor, OrderInterface $order, PromotionInterface $promotion)
 {
     $order->countItems()->willReturn(0);
     $order->getPromotionSubjectTotal()->willReturn(0);
     $distributor->distribute(Argument::any())->shouldNotBeCalled();
     $this->execute($order, ['percentage' => 0.1], $promotion);
 }
 function it_does_nothing_if_promotion_amount_is_0(OrderInterface $order, PromotionInterface $promotion, ProportionalIntegerDistributorInterface $proportionalIntegerDistributor)
 {
     $order->countItems()->willReturn(0);
     $order->getPromotionSubjectTotal()->willReturn(1000);
     $proportionalIntegerDistributor->distribute(Argument::any())->shouldNotBeCalled();
     $this->execute($order, ['amount' => 0], $promotion);
 }
 /**
  * {@inheritdoc}
  */
 public function execute(PromotionSubjectInterface $subject, array $configuration, PromotionInterface $promotion)
 {
     if (!$this->isSubjectValid($subject)) {
         return false;
     }
     $channelCode = $subject->getChannel()->getCode();
     if (!isset($configuration[$channelCode])) {
         return false;
     }
     try {
         $this->isConfigurationValid($configuration[$channelCode]);
     } catch (\InvalidArgumentException $exception) {
         return false;
     }
     $promotionAmount = $this->calculateAdjustmentAmount($subject->getPromotionSubjectTotal(), $configuration[$channelCode]['amount']);
     if (0 === $promotionAmount) {
         return false;
     }
     $itemsTotals = [];
     foreach ($subject->getItems() as $item) {
         $itemsTotals[] = $item->getTotal();
     }
     $splitPromotion = $this->proportionalDistributor->distribute($itemsTotals, $promotionAmount);
     $this->unitsPromotionAdjustmentsApplicator->apply($subject, $promotion, $splitPromotion);
     return true;
 }
Exemplo n.º 4
0
 /**
  * {@inheritdoc}
  */
 public function execute(PromotionSubjectInterface $subject, array $configuration, PromotionInterface $promotion)
 {
     if (!$this->isSubjectValid($subject)) {
         return;
     }
     $this->isConfigurationValid($configuration);
     $promotionAmount = $this->calculateAdjustmentAmount($subject->getPromotionSubjectTotal(), $configuration['amount']);
     if (0 === $promotionAmount) {
         return;
     }
     $itemsTotals = [];
     foreach ($subject->getItems() as $item) {
         $itemsTotals[] = $item->getTotal();
     }
     $splitPromotion = $this->proportionalDistributor->distribute($itemsTotals, $promotionAmount);
     $this->unitsPromotionAdjustmentsApplicator->apply($subject, $promotion, $splitPromotion);
 }
 /**
  * {@inheritdoc}
  */
 public function execute(PromotionSubjectInterface $subject, array $configuration, PromotionInterface $promotion)
 {
     /** @var OrderInterface $subject */
     if (!$this->isSubjectValid($subject)) {
         return;
     }
     $this->isConfigurationValid($configuration);
     $promotionAmount = $this->calculateAdjustmentAmount($subject->getPromotionSubjectTotal(), $configuration['percentage']);
     if (0 === $promotionAmount) {
         return;
     }
     $itemsTotal = [];
     foreach ($subject->getItems() as $orderItem) {
         $itemsTotal[] = $orderItem->getTotal();
     }
     $splitPromotion = $this->distributor->distribute($itemsTotal, $promotionAmount);
     $this->unitsPromotionAdjustmentsApplicator->apply($subject, $promotion, $splitPromotion);
 }
 function it_does_not_apply_discount_if_promotion_amount_is_0(ChannelInterface $channel, OrderInterface $order, PromotionInterface $promotion, ProportionalIntegerDistributorInterface $proportionalIntegerDistributor)
 {
     $order->getChannel()->willReturn($channel);
     $channel->getCode()->willReturn('WEB_US');
     $order->countItems()->willReturn(0);
     $order->getPromotionSubjectTotal()->willReturn(1000);
     $proportionalIntegerDistributor->distribute(Argument::any())->shouldNotBeCalled();
     $this->execute($order, ['WEB_US' => ['amount' => 0]], $promotion)->shouldReturn(false);
 }