public function store(Request $request) { $token = Session('_token'); $product_id = $request->get('product_id'); $quantity = $request->get('quantity'); $price = Product::find($product_id)->price; Cart::create(['product_id' => $product_id, 'quantity' => $quantity, '_token' => $token, 'price' => $price]); return redirect('cart')->with(['message' => 'Le produit a été ajouté dans votre panier']); }
public function store(Request $request) { $token = $request->get('_token'); $quant = $request->get('quantity'); $product_id = $request->get('product_id'); $price = Product::find($product_id)->price; $cart = Cart::create(['product_id' => $product_id, 'token' => $token, 'price' => $price, 'quantity' => $quant]); $cart_id = $cart->id; Command_unf::create(['product_id' => $product_id, 'cart_id' => $cart_id, 'token' => $token, 'price' => $price, 'quantity' => $quant]); return redirect('/')->with(['cart-store' => 'Le produit a été ajouté à votre panier !', 'alert' => 'success']); }
public function addToCart() { session_start(); if ($_SESSION) { if ($_SESSION['cart']) { // dd($_SESSION); $rules = ['amount' => 'required|numeric', 'book' => 'required|numeric|exists:books,id']; foreach ($_SESSION['cart'] as $cart_item) { $validator = \Validator::make($cart_item, $rules); if ($validator->fails()) { return \Redirect::to('index')->with('error', 'book couldnt be added'); } dd(\Auth::user()->id); $member_id = \Auth::user()->id; $book_id = $cart_item['book']; $amount = $cart_item['amount']; $book = \App\Book::find($book_id); $total = $amount * $book->price; //checking existance and count in the cart $count = \App\Cart::where('book_id', '=', $book_id)->where('member_id', '=', $member_id)->count(); $cart = ['member_id' => $member_id, 'book_id' => $book_id, 'amount' => $amount, 'total' => $total]; \App\Cart::create($cart); } session_unset(); } } else { // dd('stop'); //VALIDATION // dd('s213s'); $rules = ['amount' => 'required|numeric', 'book' => 'required|numeric|exists:books,id']; $validator = \Validator::make(\Request::all(), $rules); if ($validator->fails()) { return Redirect::to('index')->with('error', 'book couldnt be added'); } $member_id = \Auth::user()->id; $book_id = \Request::get('book'); $amount = \Request::get('amount'); $book = \App\Book::find($book_id); $total = $amount * $book->price; //checking existance and count in the cart $count = \App\Cart::where('book_id', '=', $book_id)->where('member_id', '=', $member_id)->count(); // dd($count); // if ($count) // return \Redirect::to('index')->with('error', 'That book already exists in your cart'); $cart = ['member_id' => $member_id, 'book_id' => $book_id, 'amount' => $amount, 'total' => $total]; //uslovie esli ne avtorizovan to v sessiyu // \Session::push('cart.items', $cart); // dd(\Session::get('cart.items')); \App\Cart::create($cart); } return \Redirect::route('cart', compact($cart)); }
public function store() { if (\Auth::user()) { $input = Request(); $input = ['cust_id' => \Auth::user()->id, 'product_id' => $_POST['product_id']]; $present = Cart::where("product_id", $_POST['product_id'])->where("cust_id", \Auth::User()->id)->take(1)->get()->toArray(); if (!$present) { $cart = Cart::create($input); } $present = null; return redirect('pages/cart'); } else { return redirect('auth/login'); } }
public function addAction($id) { $product = Product::find($id); if ($product) { $cart = Cart::where(['user_id' => Auth::user()->id, 'product_id' => $product->id])->get(); if ($cart->isEmpty()) { Cart::create(['user_id' => Auth::user()->id, 'product_id' => $product->id, 'quantity' => 1]); Session::flash('success', "Le produit a bien été ajouté au panier."); } else { $item = $cart->first(); $item->where(['user_id' => Auth::user()->id, 'product_id' => $product->id])->update(['quantity' => $item->quantity + 1]); } } else { Session::flash('success', "Echec de l'ajout du produit au panier"); } return redirect()->route('user.cart'); }
public function postAddToCart(Request $request) { $this->validate($request, ['item' => 'required|numeric|exists:items,id']); $user_id = Auth::user()->id; $item_id = Input::get('item'); $amount = 1; $item = Item::find($item_id); $total = $amount * $item->price; $carts = Cart::with('Items')->where('user_id', $user_id)->get(); $item_stock = $item->stock; if ($item->stock < 1) { return redirect('/')->withErrors('Ce produit n\'est plus disponible'); } Cart::create(['user_id' => $user_id, 'item_id' => $item_id, 'amount' => $amount, 'total' => $total]); $item->decrement('stock'); $last_timestamp = Cart::with('Items')->where('user_id', $user_id)->orderBy('created_at', 'desc')->first()->created_at; Auth::user()->last_cart_timestamp = $last_timestamp; Auth::user()->save(); return redirect('/'); }
public function addToCart($id, $number = 1) { if (\Request::cookie('shoppingCart')) { $cartData = shoppingCart::getCart(); $cart = unserialize($cartData->data); $cart->addToCart($id, $number); $sCart = serialize($cart); $cartData->data = $sCart; $cartData->save(); } else { $cart = new shoppingCart(); $cart->addToCart($id, $number); $sCart = serialize($cart); $ip = $_SERVER['REMOTE_ADDR']; $now = \Carbon\Carbon::now()->toDateTimeString(); $token = md5($ip . $now); \Cookie::queue('shoppingCart', $token); \App\Cart::create(['key' => $token, 'data' => $sCart]); } return redirect()->back(); }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * * @return \Illuminate\Http\Response */ public function store(Request $request) { Cart::create(['user_id' => Auth::user()->id, 'product_id' => $request->get('productId')]); return back(); }
/** * Show the form for creating a new resource. * * @return \Illuminate\Http\Response */ public function create(Request $request) { Cart::create(['name' => $request['name'], 'email' => $request['email'], 'order_details' => $request['order'], 'address' => $request['address'], 'mobile' => $request["mobile"]]); }
public function paid() { $user_id = \Auth::user()->id; $cart = new cartController(); $date = date('Y/m/d H:i:s'); $cartContents = $cart->getCartSession(); $carttable = \App\Cart::orderBy('id', 'DESC')->first(); $orderid = $carttable['id'] + 1; foreach ($cartContents as $product => $data) { $orderdata = ['id' => $orderid, 'user_id' => $user_id, 'product_id' => $product, 'amount' => $data['amount'], 'paid' => $date, 'status' => 'paid']; $order = \App\Cart::create($orderdata); $product = \App\Product::where('product_id', $product)->first(); $product->stock = $product->stock - $data['amount']; $product->save(); $cart->destroy($product); } return view('pages/shop/paid'); }
public function addTicketToCart(Request $request) { if (\Session::get('cart_id')) { $customer_id = \Session::get('cart_id'); } else { $customer_id = str_random(50); \Session::put('cart_id', $customer_id); } BandTicketSale::create(['cart_id' => $customer_id, 'product_id' => $request->input('product'), 'band_name' => $request->input('band_name')]); $size = 'onesize'; $item = $request->input('product'); if (!$this->handler->checkInventory($item, $size)) { $this->handler->checkoutAmt(); return ['failure' => 'Sorry! This is out of stock now! :(']; } // Session::forget('cart_id'); if (\Session::get('cart_id')) { $customer_id = \Session::get('cart_id'); } else { $customer_id = str_random(50); \Session::put('cart_id', $customer_id); } // $item = Input::get('product_id'); if (\App\Cart::where('customer_id', $customer_id)->where('product_id', $item)->where('size', $size)->pluck('quantity')) { $quantit = \App\Cart::where('customer_id', $customer_id)->where('product_id', $item)->where('size', $size)->pluck('quantity'); $cart = \App\Cart::where('customer_id', $customer_id)->where('product_id', $item)->where('size', $size)->first(); $cart->customer_id = $customer_id; $cart->product_id = $item; $cart->size = $size; $cart->quantity = $quantit + 1; $cart->save(); //recalculate the cart $this->handler->checkoutAmt(); return $this->handler->countItems() + 1; } else { $cart = \App\Cart::create(['customer_id' => $customer_id, 'size' => $size, 'product_id' => $item, 'quantity' => 1]); return $this->handler->countItems() + 1; } }
/** * Add to cart item that user choose * Move the hook to cart Database *@param int $id */ public function addToCart($id) { $produk = Product::findOrFail($id); Auth::loginUsingId(1); $user = Auth::user()->id; $addToCart = Cart::create(['product_id' => $produk->id, 'user_id' => $user]); return 'Berhasil Memasukan data ke cart list'; }