function it_does_nothing_if_target_quantity_is_below_0($orderItemUnitFactory, OrderItemInterface $orderItem)
 {
     $orderItem->getQuantity()->willReturn(3);
     $orderItemUnitFactory->createForItem(Argument::any())->shouldNotBeCalled();
     $orderItem->addUnit(Argument::any())->shouldNotBeCalled();
     $orderItem->removeUnit(Argument::any())->shouldNotBeCalled();
     $this->modify($orderItem, -10);
 }
 /**
  * @param OrderItemInterface $orderItem
  * @param int $decreaseBy
  */
 private function decreaseUnitsNumber(OrderItemInterface $orderItem, $decreaseBy)
 {
     foreach ($orderItem->getUnits() as $unit) {
         if (0 >= $decreaseBy--) {
             break;
         }
         $orderItem->removeUnit($unit);
     }
 }
Esempio n. 3
0
 /**
  * @param OrderInterface $order
  * @param OrderItemInterface $item
  */
 private function resolveOrderItem(OrderInterface $order, OrderItemInterface $item)
 {
     foreach ($order->getItems() as $existingItem) {
         if ($item->equals($existingItem)) {
             $this->orderItemQuantityModifier->modify($existingItem, $existingItem->getQuantity() + $item->getQuantity());
             return;
         }
     }
     $order->addItem($item);
 }
Esempio n. 4
0
 function it_changes_quantity_of_an_item_if_same_order_item_already_exists(OrderInterface $order, OrderItemInterface $existingItem, OrderItemInterface $newItem, OrderItemQuantityModifierInterface $orderItemQuantityModifier, OrderProcessorInterface $orderProcessor)
 {
     $order->getItems()->willReturn([$existingItem]);
     $newItem->equals($existingItem)->willReturn(true);
     $existingItem->getQuantity()->willReturn(2);
     $newItem->getQuantity()->willReturn(3);
     $order->addItem($existingItem)->shouldNotBeCalled();
     $orderItemQuantityModifier->modify($existingItem, 5)->shouldBeCalled();
     $orderProcessor->process($order)->shouldBeCalled();
     $this->addToOrder($order, $newItem);
 }
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
 function it_merges_equal_items(OrderItemInterface $item1, OrderItemInterface $item2)
 {
     $item1->setOrder($this)->shouldBeCalled();
     $item1->equals($item2)->willReturn(true);
     $item2->equals($item1)->willReturn(true);
     $item1->merge($item2, false)->willReturn($this)->shouldBeCalled();
     $this->addItem($item1)->addItem($item2);
     $this->countItems()->shouldReturn(1);
 }
Esempio n. 7
0
 function it_calculates_correct_total_when_adjustment_is_bigger_than_cost(OrderItemInterface $item, AdjustmentInterface $adjustment)
 {
     $item->getTotal()->willReturn(45000);
     $item->equals(Argument::any())->willReturn(false);
     $item->setOrder($this)->shouldBeCalled();
     $adjustment->isNeutral()->willReturn(false);
     $adjustment->getAmount()->willReturn(-100000);
     $adjustment->setAdjustable($this)->shouldBeCalled();
     $this->addItem($item);
     $this->addAdjustment($adjustment);
     $this->getTotal()->shouldReturn(0);
 }
Esempio n. 8
0
 /**
  * {@inheritdoc}
  */
 public function merge(OrderItemInterface $orderItem, $throwOnInvalid = true)
 {
     if ($throwOnInvalid && !$orderItem->equals($this)) {
         throw new \RuntimeException('Given item cannot be merged.');
     }
     if ($this !== $orderItem) {
         $this->quantity += $orderItem->getQuantity();
     }
     return $this;
 }
Esempio n. 9
0
 function it_recalculates_its_total_properly_after_adjustment_amount_change(AdjustmentInterface $adjustment1, AdjustmentInterface $adjustment2, OrderItemInterface $orderItem)
 {
     $orderItem->recalculateUnitsTotal()->shouldBeCalledTimes(2);
     $adjustment1->isNeutral()->willReturn(false);
     $adjustment1->setAdjustable($this)->shouldBeCalled();
     $adjustment1->getAmount()->willReturn(100);
     $adjustment2->isNeutral()->willReturn(false);
     $adjustment2->setAdjustable($this)->shouldBeCalled();
     $adjustment2->getAmount()->willReturn(50);
     $this->addAdjustment($adjustment1);
     $this->addAdjustment($adjustment2);
     $adjustment2->getAmount()->willReturn(150);
     $this->recalculateAdjustmentsTotal();
     $this->getTotal()->shouldReturn(1250);
 }
Esempio n. 10
0
 function it_throws_exception_when_merging_unequal_item(OrderItemInterface $item)
 {
     $item->equals($this)->willReturn(false);
     $this->shouldThrow(new \RuntimeException('Given item cannot be merged.'))->duringMerge($item);
 }
Esempio n. 11
0
 /**
  * {@inheritdoc}
  */
 public function clearAdjustments()
 {
     $this->adjustments->clear();
     $this->recalculateAdjustmentsTotal();
     $this->orderItem->recalculateUnitsTotal();
 }
Esempio n. 12
0
 function it_recalculates_adjustments_on_adjustable_entity_on_amount_change(OrderInterface $order, OrderItemInterface $orderItem, OrderItemUnitInterface $orderItemUnit)
 {
     $order->addAdjustment($this->getWrappedObject())->shouldBeCalled();
     $this->setAdjustable($order);
     $order->recalculateAdjustmentsTotal()->shouldBeCalled();
     $this->setAmount(200);
     $order->removeAdjustment($this->getWrappedObject())->shouldBeCalled();
     $orderItem->addAdjustment($this->getWrappedObject())->shouldBeCalled();
     $this->setAdjustable($orderItem);
     $orderItem->recalculateAdjustmentsTotal()->shouldBeCalled();
     $this->setAmount(300);
     $orderItem->removeAdjustment($this->getWrappedObject())->shouldBeCalled();
     $orderItemUnit->addAdjustment($this->getWrappedObject())->shouldBeCalled();
     $this->setAdjustable($orderItemUnit);
     $orderItemUnit->recalculateAdjustmentsTotal()->shouldBeCalled();
     $this->setAmount(400);
 }
 function it_restricts_max_item_quantity_to_the_stated_limit(OrderItemQuantityModifierInterface $itemQuantityModifier, OrderItemInterface $orderItem)
 {
     $orderItem->getQuantity()->willReturn(0);
     $itemQuantityModifier->modify($orderItem, 1000)->shouldBeCalled();
     $this->modify($orderItem, 9999);
 }
Esempio n. 14
0
 public function equals(SyliusOrderItemInterface $item)
 {
     /** @var $item OrderItem */
     return $this->product === $item->getProduct() || $this->product->getId() == $item->getProduct()->getId();
 }
Esempio n. 15
0
 public function calculateTotal()
 {
     $this->calculateAdjustmentsTotal();
     $this->total = $this->orderItem->getUnitPrice() + $this->adjustmentsTotal;
 }