Esempio n. 1
0
 function it_has_correct_total_after_adjustment_add_and_remove(AdjustmentInterface $adjustment1, AdjustmentInterface $adjustment2, AdjustmentInterface $adjustment3, OrderItemInterface $orderItem)
 {
     $orderItem->recalculateUnitsTotal()->shouldBeCalledTimes(4);
     $adjustment1->isNeutral()->willReturn(false);
     $adjustment1->setAdjustable($this)->shouldBeCalled();
     $adjustment1->isLocked()->willReturn(false);
     $adjustment1->setAdjustable(null)->shouldBeCalled();
     $adjustment1->getAmount()->willReturn(100);
     $adjustment2->isNeutral()->willReturn(false);
     $adjustment2->setAdjustable($this)->shouldBeCalled();
     $adjustment2->getAmount()->willReturn(50);
     $adjustment3->isNeutral()->willReturn(false);
     $adjustment3->setAdjustable($this)->shouldBeCalled();
     $adjustment3->getAmount()->willReturn(250);
     $this->addAdjustment($adjustment1);
     $this->addAdjustment($adjustment2);
     $this->getTotal()->shouldReturn(1150);
     $this->addAdjustment($adjustment3);
     $this->removeAdjustment($adjustment1);
     $this->getTotal()->shouldReturn(1300);
 }
Esempio n. 2
0
 function it_calculates_its_total_properly_after_adjustments_modification(AdjustmentInterface $adjustment1, AdjustmentInterface $adjustment2, AdjustmentInterface $adjustment3, OrderItemInterface $orderItem)
 {
     $adjustment1->isNeutral()->willReturn(false);
     $adjustment1->setAdjustable($this)->shouldBeCalled();
     $adjustment1->isLocked()->willReturn(false);
     $adjustment1->setAdjustable(null)->shouldBeCalled();
     $adjustment2->isNeutral()->willReturn(false);
     $adjustment2->setAdjustable($this)->shouldBeCalled();
     $adjustment3->isNeutral()->willReturn(false);
     $adjustment3->setAdjustable($this)->shouldBeCalled();
     $adjustment1->getAmount()->willReturn(100);
     $adjustment2->getAmount()->willReturn(50);
     $adjustment3->getAmount()->willReturn(250);
     $this->addAdjustment($adjustment1);
     $this->addAdjustment($adjustment2);
     $this->setOrderItem($orderItem);
     $orderItem->getUnitPrice()->willReturn(1000);
     $this->calculateTotal();
     $this->getTotal()->shouldReturn(1150);
     $this->removeAdjustment($adjustment1);
     $this->addAdjustment($adjustment3);
     $this->calculateTotal();
     $this->getTotal()->shouldReturn(1300);
 }
Esempio n. 3
0
 function it_removes_adjustments_recursively_by_type_properly(AdjustmentInterface $orderPromotionAdjustment, AdjustmentInterface $orderTaxAdjustment, OrderItemInterface $item)
 {
     $orderPromotionAdjustment->getType()->willReturn('promotion');
     $orderPromotionAdjustment->isNeutral()->willReturn(true);
     $orderPromotionAdjustment->setAdjustable($this)->shouldBeCalled();
     $orderPromotionAdjustment->isLocked()->willReturn(false);
     $orderTaxAdjustment->getType()->willReturn('tax');
     $orderTaxAdjustment->isNeutral()->willReturn(true);
     $orderTaxAdjustment->setAdjustable($this)->shouldBeCalled();
     $orderTaxAdjustment->isLocked()->willReturn(false);
     $this->addAdjustment($orderPromotionAdjustment);
     $this->addAdjustment($orderTaxAdjustment);
     $this->addItem($item);
     $item->removeAdjustmentsRecursively('tax')->shouldBeCalled();
     $orderTaxAdjustment->setAdjustable(null)->shouldBeCalled();
     $this->removeAdjustmentsRecursively('tax');
     $this->hasAdjustment($orderPromotionAdjustment)->shouldReturn(true);
     $this->hasAdjustment($orderTaxAdjustment)->shouldReturn(false);
 }
Esempio n. 4
0
 /**
  * {@inheritdoc}
  */
 public function removeAdjustment(AdjustmentInterface $adjustment)
 {
     if (!$adjustment->isLocked() && $this->hasAdjustment($adjustment)) {
         $this->adjustments->removeElement($adjustment);
         $this->subtractFromAdjustmentsTotal($adjustment);
         $adjustment->setAdjustable(null);
     }
 }
Esempio n. 5
0
 /**
  * {@inheritdoc}
  */
 public function removeAdjustment(AdjustmentInterface $adjustment)
 {
     if ($adjustment->isLocked() || !$this->hasAdjustment($adjustment)) {
         return;
     }
     $this->adjustments->removeElement($adjustment);
     $this->subtractFromAdjustmentsTotal($adjustment);
     $this->orderItem->recalculateUnitsTotal();
     $adjustment->setAdjustable(null);
 }
Esempio n. 6
0
 /**
  * {@inheritdoc}
  */
 public function removeAdjustment(AdjustmentInterface $adjustment)
 {
     if (!$adjustment->isLocked() && $this->hasAdjustment($adjustment)) {
         $adjustment->setAdjustable(null);
         $this->adjustments->removeElement($adjustment);
     }
     return $this;
 }