Cart\Cart::update PHP Method

update() public method

Update an item in the cart.
public update ( string $itemId, string $key, mixed $value ) : string
$itemId string
$key string
$value mixed
return string
    public function update($itemId, $key, $value)
    {
        $item = $this->find($itemId);
        if (!$item) {
            throw new \InvalidArgumentException(sprintf('Item [%s] does not exist in cart.', $itemId));
        }
        $item->{$key} = $value;
        return $item->id;
    }

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