Пример #1
0
 /**
  * @param CartInterface $cart
  * @param CartItemInterface $item
  */
 private function resolveCartItem(CartInterface $cart, CartItemInterface $item)
 {
     foreach ($cart->getItems() as $existingItem) {
         if ($item->equals($existingItem)) {
             $this->orderItemQuantityModifier->modify($existingItem, $existingItem->getQuantity() + $item->getQuantity());
             return;
         }
     }
     $cart->addItem($item);
 }
Пример #2
0
 function it_changes_quntity_of_item_if_same_cart_item_already_exists(OrderProcessorInterface $orderProcessor, OrderItemQuantityModifierInterface $orderItemQuantityModifier, CartInterface $cart, CartItemInterface $newItem, CartItemInterface $existingItem)
 {
     $cart->getItems()->willReturn([$existingItem]);
     $newItem->equals($existingItem)->willReturn(true);
     $existingItem->getQuantity()->willReturn(2);
     $newItem->getQuantity()->willReturn(3);
     $cart->addItem($existingItem)->shouldNotBeCalled();
     $orderItemQuantityModifier->modify($existingItem, 5)->shouldBeCalled();
     $orderProcessor->process($cart)->shouldBeCalled();
     $this->addToCart($cart, $newItem);
 }