public function checkout(Request $request) { \Stripe\Stripe::setApiKey('sk_test_gzviHPn6POLwymNxUXTpFhhG'); $token = $request->input('stripeToken'); //Retriieve cart information $cart = Cart::where('user_id', Auth::user()->id)->first(); $items = $cart->cartItems; $total = 0; foreach ($items as $item) { $total += $item->product->price; } if (Auth::user()->charge($total * 100, ['source' => $token, 'receipt_email' => Auth::user()->email])) { $order = new Order(); $order->total_paid = $total; $order->user_id = Auth::user()->id; $order->save(); foreach ($items as $item) { $orderItem = new OrderItem(); $orderItem->order_id = $order->id; $orderItem->product_id = $item->product->id; $orderItem->file_id = $item->product->file->id; $orderItem->save(); CartItem::destroy($item->id); } return redirect('/order/' . $order->id); } else { return redirect('/cart'); } }
public function postIndex(Request $request) { $cart = new Cart(); $prescription = NULL; if ($request->hasFile('prescription')) { $file = $request->file('prescription'); $request->file('prescription')->move('uploads', $file->getClientOriginalName()); $prescription = $file->getClientOriginalName(); } $order = new Order(); $order->fullname = $request->fullname; $order->email = $request->emailaddress; $order->address = $request->address; $order->mobile = $request->mobile; $order->prescription = $prescription; $order->save(); for ($i = 0; $i < count($request->product_id); $i++) { $orderItem = new OrderItem(); $orderItem->order_id = $order->id; $orderItem->product_id = $request->product_id[$i]; $orderItem->quantity = $request->quantity[$i]; $orderItem->save(); } $order_details = Order::find($order->id); $data = array('order_details' => $order_details, 'total' => $cart->getTotal(), 'fullname' => $request->fullname, 'emailaddress' => $request->emailaddress); Mail::send('emails.order', ['data' => $data], function ($m) use($data) { $m->from('*****@*****.**', 'EMarket'); $m->to($data['emailaddress'], $data['fullname'])->subject('Order Placed Successfully'); }); $cart->clear(); return redirect('checkout/placed/' . $order->id); }
public function test() { $orderItems = OrderItem::select(DB::raw('product_id, count(product_id) as count'))->whereRaw('MONTH(created_at)=6')->groupBy('product_id')->take(5)->orderBy('count')->get(); foreach ($orderItems as $i => $orderItem) { echo $orderItem->product->name . '<br>'; } }
public function orderTotal($orderId) { $items = OrderItem::where('order_id', '=', $orderId)->get(); $total = 0; foreach ($items as $item) { $total += $item->quantity * $item->price; } return $total; }
public function download($orderId, $filename) { $fileid = \App\File::where('filename', $filename)->first(); $orderItem = OrderItem::where('order_id', '=', $orderId)->where('file_id', $fileid->id)->first(); if (!$orderItem) { redirect('/failed'); } $entry = \App\File::where('filename', $filename)->first(); $file = Storage::disk('local')->get($entry->filename); return (new Response($file, 200))->header('Content-Type', $entry->mime); }
/** * Run the database seeds. * * @return void */ public function run() { OrderItem::create(['order_id' => 1, 'product_id' => 2, 'quantity' => 1, 'subtotal_price' => 15]); OrderItem::create(['order_id' => 2, 'product_id' => 1, 'quantity' => 1, 'subtotal_price' => 25]); OrderItem::create(['order_id' => 2, 'product_id' => 2, 'quantity' => 1, 'subtotal_price' => 15]); OrderItem::create(['order_id' => 3, 'product_id' => 2, 'quantity' => 2, 'subtotal_price' => 30]); OrderItem::create(['order_id' => 4, 'product_id' => 3, 'quantity' => 1, 'subtotal_price' => 1000]); OrderItem::create(['order_id' => 5, 'product_id' => 1, 'quantity' => 2, 'subtotal_price' => 50]); OrderItem::create(['order_id' => 6, 'product_id' => 2, 'quantity' => 1, 'subtotal_price' => 15]); OrderItem::create(['order_id' => 7, 'product_id' => 2, 'quantity' => 2, 'subtotal_price' => 30]); }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * * @return \Illuminate\Http\Response */ public function store(Request $request) { $qtys = $request->get('qty'); $charge = Cart::where('user_id', Auth::user()->id)->get()->map(function ($c) { return $c->product; })->sum(function ($p) use($qtys) { return $p->price * $qtys[$p->id]; }); $order = Order::create(['user_id' => Auth::user()->id, 'note' => $request->get('note'), 'charge' => $charge, 'status' => 'Cooking', 'address' => $request->get('address')]); foreach ($qtys as $pid => $qty) { OrderItem::create(['product_id' => $pid, 'order_id' => $order->id, 'qty' => $qty]); } Cart::where('user_id', Auth::user()->id)->delete(); return redirect('/')->with('success', 'Your order will be delivered to ' . $request->get('address') . ' soon.'); }
public function run() { $faker = $this->getFaker(); $orders = Order::all(); $equipment = Equipment::all()->toArray(); foreach ($orders as $order) { $used = []; for ($i = 0; $i < rand(1, 5); $i++) { $product = $faker->randomElement($equipment); if (!in_array($equipment["id"], $used)) { $id = $equipment["id"]; $price = $equipment["price"]; $quantity = rand(1, 3); OrderItem::create(["order_id" => $order->id, "equipment_id" => $id, "price" => $price, "quantity" => $quantity]); $used[] = $equipment["id"]; } } } }
public function infoProducts($products, $id) { $allPrice = 0; $convert = array(); $infoProduct = array(); foreach ($products as $item) { $infoItem = Products::getPriceItem($item['id']); $infoProduct[] = ['info' => $infoItem, 'count' => $item['count']]; if ($infoItem[0]->newPrice != '0' || $infoItem[0]->newPrice != NULL) { $Price = $infoItem[0]->newPrice; $allPrice = $allPrice + $infoItem[0]->newPrice * $item['count']; } else { $Price = $infoItem[0]->price; $allPrice = $allPrice + $infoItem[0]->price * $item['count']; } $convert[] = ['products_id' => $item['id'], 'count' => $item['count'], 'price' => $Price, 'title' => $infoItem[0]->title, 'order_id' => $id]; OrderItem::insertItemOrder($convert); } $info = ['infoProduct' => $infoProduct, 'allPrice' => $allPrice]; return $info; }
public function show($id) { $orderItems = OrderItem::where('order_id', $id)->get(); return view('order.show', compact('orderItems')); }
public function getItems(Request $request) { $items = OrderItem::with('product')->where('order_id', $request->get('order_id'))->get(); return json_encode($items); }
public function review() { $rules = array('name' => 'required|min:5', 'email' => 'required|email', 'address1' => 'required|min:5', 'city' => 'required', 'postcode' => 'required|min:3', 'country' => 'required|max:2', 'payment_method' => 'required|max:6'); $validator = Validator::make(Input::all(), $rules); if ($validator->fails()) { return redirect()->back()->withErrors($validator->errors())->withInput(); } else { $addressinfo = Input::except('_token', 'page', 'cartjson'); $order = Order::create($addressinfo); $order->ordernumber = "LEAF-" . mt_rand(100000, 999999); $cart = json_decode(Input::get('cartjson')); $totalamount = 0; foreach ($cart->items as $cartitem) { $item = Item::find($cartitem->itemid); if ($item->id == Item::SHIPPING) { $shipping = $this->calculateShipping($order); $orderitem = OrderItem::create(["item_id" => $item->id, "order_id" => $order->id, "itemprice" => $shipping, "amount" => 1]); $totalamount += $shipping; } else { $orderitem = OrderItem::create(["item_id" => $item->id, "order_id" => $order->id, "itemprice" => $item->price, "amount" => $cartitem->itemamount]); $totalamount += $item->price * $orderitem->amount; } $orderitem->save(); } $order->totalamount = $totalamount; $order->save(); return view('review', ["order" => $order]); } }
public function putPlace(Request $request) { $validator = Validator::make($request->input(), ['addr' => 'required|string', 'phone' => 'required|numeric'], ['addr.required' => 'The address field is required.', 'phone.required' => 'The phone number is required.', 'phone.numeric' => 'The phone number must be numeric.']); if ($validator->fails()) { return redirect('order/place')->withErrors($validator)->withInput(); } $order = Order::create(['addr' => $request->input('addr'), 'phone' => $request->input('phone'), 'user_id' => $request->user()->id]); $order->save(); $cart = $request->session()->get('cart', array()); foreach ($cart as $product_id => $count) { $product = Product::find($product_id); $orderItem = OrderItem::create(['order_id' => $order->id, 'product_id' => $product->id, 'weight' => $count, 'price' => $product->price]); $orderItem->save(); } $request->session()->forget('cart'); //The cart should be empty after an order. return redirect('order/show/' . $order->id); }
public function makeOrder() { $this->checkAJAX(); if (empty(Cart::content()->toArray())) { exit(1); } $order = new Order(); $order->user_id = Auth::user()->id; $order->total_price = $this->price; $order->save(); foreach (Cart::content() as $item) { $line = new OrderItem(); $line->product_id = $item->id; $line->quantity = $item->qty; $line->subtotal_price = $item->subtotal; $line->order()->associate($order); $line->save(); } Cart::destroy(); Auth::logout(); }
public function getBestSellingProduct() { $products = OrderItem::select(DB::raw('product_id, count(product_id) as count'))->whereRaw('MONTH(created_at)=6')->groupBy('product_id')->take(5)->orderBy('count')->get(); return $products; }
/** * Show the form for editing the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function edit($id) { $order = Order::findOrFail($id); $order_item = OrderItem::where('order_id', $id)->get(); //오더 아이템의 갯수만큼 텍스트 박스를 늘려서, 값을 넣어야한다. $customer = Customer::where('order_relationship', $id)->first(); if ($customer == null) { $customer_name = substr($order->customer_name, 0, 6); $customer = Customer::where('first_name', 'LIKE', "%{$customer_name}%")->first(); } // 여기를 contact_number로 변경하고 없 //$customer = Customer::where('first_name','LIKE',"%$customer_name%")->get(); /* product_name 컬럼안의 갯수만큼 배열 변수를 만들어야한다. */ //$order->product_name_arr = explode(",",$order->product_name); //갯수를 구한다. //dd($order->product_name_arr); return view('order.edit', compact('order', 'customer', 'order_item')); }
protected function saveOrderItem($item, $order_id) { OrderItem::create(['quantity' => $item->quantity, 'price' => $item->price, 'product_id' => $item->id, 'order_id' => $order_id]); }
/** * Save order item * * @param $name * @param $amount * @param $orderId */ public function save($name, $amount, $orderId) { OrderItem::create(['name' => $name, 'amount' => $amount, 'order_id' => $orderId]); }