/** * add a checkout * @param Request $request [description] * @return [type] [description] */ public function addCheckout(Request $request) { $checkout = new Checkout(); $checkout = $request->all(); Checkout::create($checkout); //update status room Room::where('name', $checkout['room_name'])->update(array('status' => 'A')); return redirect()->route('listroom_com'); }
public function postCheckout() { //Take all fields from post form $input = Input::all(); // do the validation ---------------------------------- // validate against the inputs from our form------- $validator = Validator::make($input, Checkout::$rules); if ($validator->fails()) { // get the error messages from the validator $messages = $validator->messages(); // redirect our user back to the form with the errors from the validator //var_dump($validator->messages()); return redirect()->route('rental.checkoutForm')->withInput()->withErrors($validator)->withErrors($validator->getMessageBag()); } else { // validation successful --------------------------- $checkout = Checkout::create(['user_id' => Auth::user()->id, 'email' => Input::get('email'), 'first_name' => Input::get('first_name'), 'last_name' => Input::get('last_name'), 'address' => Input::get('address'), 'zip' => Input::get('zip'), 'country' => Input::get('country'), 'state' => Input::get('state'), 'phone' => Input::get('phone'), 'description' => Input::get('description')]); $order_items = Cart::content(true); foreach ($order_items as $order) { DB::table('order_item')->insertGetId(['order_id' => $checkout->id, 'equipment_id' => $order['id'], 'price' => $order['price'], 'created_at' => Carbon::now(), 'updated_at' => Carbon::now()]); } var_dump($order_items); //redirect our user back to the form so they can do it all over again return redirect()->route('rental.index'); } }
public function checkout(Request $request) { //if cart is set then checkout //** if cod set payment status to cod if ($cart = Cart::content()) { //check for payment success $checkout = true; //user paymet success $payment_type = 'cod'; if ($checkout) { //get the user who made purchase $user = Sentinel::check(); //check if temp address is isset if ($request->session()->has('tmp_address')) { // $address = $request->session()->get('tmp_address'); } else { $address = $user->address; } if ($area_id = $user->area_id) { //$delivery_cost = $areas->find($area_id)->delivery_cost; } elseif ($area_id = $request->session()->get('deli_area')) { //$delivery_cost = $areas->find($area_id)->delivery_cost; } else { $area_id = "unknown"; } //dd($address); if ($request->session()->has('deli_time')) { // $deli_id = $request->session()->get('deli_time'); $dt = DB::table('deliverytimes')->where('id', $deli_id)->first(); } else { $dt = DB::table('deliverytimes')->first(); } //dd($dt); if ($dt) { $start = Carbon::parse($dt->start)->format('h:ia'); $stop = Carbon::parse($dt->stop)->format('h:ia'); $delivery_time = $start . '-' . $stop; } else { $start = Carbon::now()->format('h:ia'); $stop = Carbon::now()->format('h:ia'); $delivery_time = $start . '-' . $stop; } //dd($delivery_time); $total = Cart::total(); $areas = Area::all(); //calculate the total and delivery cost if ($total < 250) { if ($area_id) { $delivery_cost = $areas->find($area_id)->delivery_cost; } else { $delivery_cost = "0"; } } else { $delivery_cost = "0"; } $total = $total + $delivery_cost; //dd($total); //create checkout and set user to it and also set payment status $checkout = Checkout::create(['user_id' => $user->id, 'area_id' => $area_id, 'payment' => false, 'payment_type' => $payment_type, 'status' => 'not confirmed', 'deliverytime' => $delivery_time, 'total' => $total]); //dd($checkout); //if address is set then add to checkout if ($address) { $checkout->address = $address; $checkout->save(); } if ($checkout) { //create order list foreach ($cart as $order) { //dd($order); $newOrderinput = ['checkout_id' => $checkout->id, 'product_id' => $order->id, 'nos' => $order->qty, 'offer_name' => $order->offer_name, 'offered_price' => $order->price, 'pqty' => $order->options->pqty . $order->options->pqunit]; //insert offer name if ($offer_name = $order->offer_name) { $newOrderinput['offer_name'] = $offer_name; } else { $newOrderinput['offer_name'] = "no offer"; } //dd($newOrderinput); Order::create($newOrderinput); } } $checkout->status = "Order Placed"; $checkout->save(); Cart::destroy(); if ($user = Sentinel::check()) { $user = User::findorfail($user->id); Event::fire(new MadeCheckout($user, $checkout)); //temp cart gets deleted in the listener } //clear cart data } } $notification = "Thankyou. Your order has been successfully placed. <br> Continue <a href='/'>shopping</a>."; return view('site.notification', compact('notification')); }