예제 #1
0
 public function addCart()
 {
     if (count(Session::get('user_id')) == 0) {
         return redirect('Login');
     } else {
         $Pros = Products::leftJoin('shoppingcart', 'products_id', '=', 'prod_id')->where("products_id", "=", Input::get('btn_hidden_id'))->get();
         foreach ($Pros as $Pro) {
             if ($Pro->prod_id == true && $Pro->cart_user_id == true) {
                 for ($this->qtyC = $Pro->cart_pro_qty; $this->qtyC <= $Pro->cart_pro_qty; $this->qtyC++) {
                     $qtyCart = $this->qtyC += 1;
                     $this->getFullPriceProd = $Pro->Products_price * $this->qtyC;
                     DB::table('shoppingcart')->where('prod_id', "=", Input::get('btn_hidden_id'))->update(array('cart_pro_qty' => $qtyCart, 'full_prise_prod' => $this->getFullPriceProd));
                 }
                 return redirect('Shoppingcart');
                 exit;
             } else {
                 $this->qtyC = '1';
                 $this->getFullPriceProd = $Pro->Products_price * $this->qtyC;
                 DB::table('shoppingcart')->insert(['shoppingcart_prod_name' => $Pro->products_name, 'shoppingcart_prod_price' => $Pro->Products_price, 'full_prise_prod' => $this->getFullPriceProd, 'shoppingcart_prod_title' => $Pro->product_title, 'shoppingcart_prod_label' => $Pro->products_label, 'shoppingcart_prod_img' => $Pro->product_image, 'cart_pro_qty' => $this->qtyC, 'cart_user_id' => Session::get('user_id'), 'prod_id' => $Pro->products_id]);
                 return redirect('Shoppingcart');
             }
         }
     }
 }