Cart\Cart::remove PHP Method

remove() public method

Remove an item from the cart.
public remove ( string $itemId )
$itemId string
    public function remove($itemId)
    {
        $items =& $this->items;
        foreach ($items as $position => $item) {
            if ($itemId === $item->id) {
                unset($items[$position]);
            }
        }
    }

Usage Example

Beispiel #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));
     }
 }