/** * Add an item to the cart. * * @param CartItem $cartItem */ public function add(CartItem $cartItem) { $itemId = $cartItem->getId(); // if item already exists in the cart, just update the quantity, // otherwise add it as a new item if ($this->has($itemId)) { $existingItem = $this->find($itemId); $existingItem->quantity += $cartItem->quantity; } else { $this->items[] = $cartItem; } }
public function testGettingIdPropertyReturnsItemId() { $item = new CartItem(); $this->assertSame($item->getId(), $item->id); }