public function store() { $input = Input::all(); $salesman = isset($input['salesman']) ? $input['salesman'] : null; $customer = Customer::firstOrNew(['name' => $input['name'], 'address' => $input['address']]); $customer->save(); $order = new Order(); $order->customer_id = $customer->id; $order->salesman_id = $salesman; $order->date = $input['date']; $order->type = $input['type']; $order->save(); foreach ($input['box_id'] as $i => $box_id) { $orderItem = new OrderItem(); $orderItem->order_id = $order->id; $orderItem->product_id = Box::find($box_id)->product->id; $orderItem->box_id = $box_id; $orderItem->no_of_box = $input['no_of_box'][$i]; $orderItem->no_of_packs = $input['no_of_packs'][$i]; $orderItem->amount = $input['amount'][$i]; $orderItem->selling_price = $input['selling_price'][$i]; $orderItem->save(); } return view('order.addmore'); }
public function checkout(Request $request) { $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 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(); }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { //"undefined397,399," $product_id = Input::get('product_id'); $product_id = str_replace("undefined", "", $product_id); $product_id = substr($product_id, 0, -1); $product_id_arr = explode(",", $product_id); // /* $this->registProduct(); $this->registCustomer(); */ #return $request->all(); #return Input::get('price'); $order = new Order(); $order->save(); //order_id를 얻기위해 저장함 $customer = new Customer(); $customer->first_name = Input::get('first_name'); $customer->contact_email = Input::get('contact_email'); $customer->contact_number = Input::get('contact_number'); $customer->street = Input::get('street'); $customer->city = Input::get('city'); $customer->state = Input::get('state'); $customer->zip = Input::get('zip'); $customer->country = Input::get('country'); $customer->order_relationship = $order->id; $order->market_place = Input::get('market_place'); $order->customer_name = Input::get('first_name') . Input::get('last_name'); $order->order_status = 'Unshipped'; $order->customer_id = $customer->id; // 배열의 갯수만큼 반복적으로 오더_아이템을 생성 - 저장 $product_cnt = count(Input::get('product_name')); for ($i = 0; $i < $product_cnt; $i++) { $order_item = new OrderItem(); $order_item->product_id = $product_id_arr[$i]; $order_item->order_id = $order->id; $order_item->product_code = Input::get('product_name')[$i]; $order_item->size_color = Input::get('size_color')[$i]; $order_item->price = Input::get('price')[$i]; $order_item->quantity = Input::get('quantity')[$i]; $order_item->total = Input::get('total')[$i]; $order_item->sales_price = Input::get('sales_price')[$i]; $order_item->save(); } $order->sales_owner = Input::get('sales_owner'); $order->order_date = Input::get('order_date'); $order->notes = Input::get('notes'); $order->sub_total = Input::get('sub_total'); $order->vat = Input::get('vat'); $order->discount = Input::get('discount'); $order->grand_total = Input::get('grand_total'); $order->delivery_date = Input::get('delivery_date'); $order->delivery_agency = Input::get('delivery_agency'); $order->track_number = Input::get('track_number'); $order->save(); $customer->save(); return redirect()->route('orders'); }