コード例 #1
0
 /**
  * @param UpdateCartBindingModel $input
  * @param Products $product
  */
 public function update(UpdateCartBindingModel $input, Products $product)
 {
     $errors = [];
     foreach ($input->getQuantity() as $product_id => $item) {
         $check = $product->checkQuantity($product_id);
         if ($check < $item) {
             array_push($errors, "Product <b>" . $product->getName($product_id) . "</b> has max quantity: {$check}");
         }
     }
     if (count($errors) > 0) {
         $this->redirect->to('/cart')->withErrors($errors)->go();
     } else {
         $this->session->getSession()->cart = $input->getQuantity();
     }
     $this->redirect->to('/cart')->go();
 }