Exemple #1
0
 public function updateCart()
 {
     // see if we have an update for the cart
     $product_id = \CI::input()->post('product_id');
     $quantity = \CI::input()->post('quantity');
     $item = \GC::getCartItem($product_id);
     if (!$item) {
         return json_encode(['error' => lang('error_product_not_found')]);
     }
     if (intval($quantity) === 0) {
         \GC::removeItem($product_id);
         echo json_encode(['success' => true]);
     } else {
         //create a new list of relevant items
         $item->quantity = $quantity;
         $insert = \GC::insertItem(['product' => $item, 'quantity' => $quantity]);
         echo $insert;
     }
     //save the cart updates
     \GC::saveCart();
     return true;
 }