Beispiel #1
0
 function it_returns_correct_adjustments_total_by_type_recursively(AdjustmentInterface $adjustment1, OrderItemUnitInterface $orderItemUnit1, OrderItemUnitInterface $orderItemUnit2)
 {
     $adjustment1->getType()->willReturn('tax');
     $adjustment1->getAmount()->willReturn(200);
     $adjustment1->isNeutral()->willReturn(false);
     $adjustment1->setAdjustable($this)->shouldBeCalled();
     $orderItemUnit1->getOrderItem()->willReturn($this->getWrappedObject());
     $orderItemUnit1->getTotal()->willReturn(500);
     $orderItemUnit1->getAdjustmentsTotal('tax')->willReturn(150);
     $orderItemUnit1->getAdjustmentsTotal('promotion')->willReturn(30);
     $orderItemUnit2->getOrderItem()->willReturn($this->getWrappedObject());
     $orderItemUnit2->getTotal()->willReturn(300);
     $orderItemUnit2->getAdjustmentsTotal('tax')->willReturn(100);
     $orderItemUnit2->getAdjustmentsTotal('promotion')->willReturn(0);
     $this->addAdjustment($adjustment1);
     $this->addUnit($orderItemUnit1);
     $this->addUnit($orderItemUnit2);
     $this->getAdjustmentsTotalRecursively('tax')->shouldReturn(450);
     $this->getAdjustmentsTotalRecursively('promotion')->shouldReturn(30);
 }
 /**
  * @param PromotionInterface $promotion
  * @param OrderItemUnitInterface $unit
  * @param int $amount
  */
 private function addAdjustment(PromotionInterface $promotion, OrderItemUnitInterface $unit, $amount)
 {
     $adjustment = $this->adjustmentFactory->createWithData(AdjustmentInterface::ORDER_PROMOTION_ADJUSTMENT, $promotion->getName(), $amount);
     $adjustment->setOriginCode($promotion->getCode());
     $unit->addAdjustment($adjustment);
 }
Beispiel #3
0
 function it_recalculate_adjustments_on_adjustable_entity_on_neutral_change(OrderItemUnitInterface $orderItemUnit)
 {
     $orderItemUnit->addAdjustment($this->getWrappedObject())->shouldBeCalled();
     $this->setAdjustable($orderItemUnit);
     $orderItemUnit->recalculateAdjustmentsTotal()->shouldBeCalled();
     $this->setNeutral(true);
 }
 function it_creates_a_new_order_item_unit_with_given_order_item(OrderItemInterface $orderItem, OrderItemUnitInterface $orderItemUnit)
 {
     $orderItemUnit->getOrderItem()->willReturn($orderItem);
     $this->createForItem($orderItem)->shouldBeSameAs($orderItemUnit);
 }
Beispiel #5
0
 /**
  * {@inheritdoc}
  */
 public function addUnit(OrderItemUnitInterface $unit)
 {
     if ($this !== $unit->getOrderItem()) {
         throw new \LogicException('This order item unit is assigned to a different order item.');
     }
     if (!$this->hasUnit($unit)) {
         $this->units->add($unit);
         ++$this->quantity;
         $this->unitsTotal += $unit->getTotal();
         $this->recalculateTotal();
     }
 }