has() public method

Determine if an item exists in the cart.
public has ( string $itemId ) : boolean
$itemId string
return boolean
Example #1
0
 /**
  * @param Cart   $cart
  * @param string $cartItemId
  * @param int    $amount
  */
 protected function handlePOSTUpdateAmount($cart, $cartItemId, $amount)
 {
     if (!$cart->has($cartItemId)) {
         return;
     }
     if ($amount === 0) {
         $cart->remove($cartItemId);
     } else {
         $cart->update($cartItemId, 'quantity', intval($amount));
     }
 }
Example #2
0
 public function testRestore()
 {
     $item1 = new CartItem(array('name' => 'foo'));
     $item2 = new CartItem(array('name' => 'bar'));
     $storeGetReturn = array('id' => 'foo', 'items' => array($item1->toArray(), $item2->toArray()));
     $store = m::mock('Cart\\Storage\\Store');
     $store->shouldReceive('get')->times(1)->andReturn(serialize($storeGetReturn));
     $cart = new Cart('foo', $store);
     $cart->restore();
     $this->assertSame('foo', $cart->getId());
     $this->assertTrue($cart->totalUniqueItems() == 2);
     $this->assertTrue($cart->has($item1->id));
     $this->assertTrue($cart->has($item2->id));
 }