public function getItems($id) { $order = Order::find($id); if ($order) { $Orderitem = Orderitem::where('order_id', $id)->get(); return View::make('items')->with('Orderitem', $Orderitem); } }
public function success() { if (Input::get("token") && Input::get("PayerID")) { $token = Input::get('token'); $update = Order::where('token', '=', $token)->update(array("status" => 1)); $order = Order::where('token', '=', $token)->first(); $items = Orderitem::where('order_id', '=', $order->id)->get(); foreach ($items as $item) { $qt = $item->item_qt; Product::where('id', '=', $item->item_id)->decrement('stock', $qt); } return Redirect::to('product/all')->with('message', 'Votre commande a été passé !'); } }
public function show() { $addresses = Useradd::where('user_id', '=', Auth::user()->id)->get(); $orders = Order::where('orders.user_id', '=', Auth::user()->id)->leftJoin('user_adds as shipadd', 'orders.add_id', '=', 'shipadd.id')->leftJoin('user_adds as rcpadd', 'orders.rcp_id', '=', 'rcpadd.id')->select('orders.*', 'shipadd.title AS ship_title', 'shipadd.address AS ship_add', 'shipadd.address2 AS ship_add2', 'shipadd.postal AS ship_post', 'shipadd.city AS ship_city', 'shipadd.first_name AS ship_first', 'shipadd.last_name AS ship_last', 'rcpadd.title AS rcp_title', 'rcpadd.address AS rcp_add', 'rcpadd.address2 AS rcp_add2', 'rcpadd.postal AS rcp_post', 'rcpadd.city AS rcp_city', 'rcpadd.first_name AS rcp_first', 'rcpadd.last_name AS rcp_last')->orderBy('orders.date', 'DESC')->get(); // on va récupérer les produits de chaque commande // commence par récupérer l'id de chaque commande $orders_id = Order::where('orders.user_id', '=', Auth::user()->id)->select('orders.id')->orderBy('orders.date', 'DESC')->get(); $items = array(); // rangés par commandes foreach ($orders_id->toArray() as $row => $ord) { $i = Orderitem::where('order_id', '=', $ord['id'])->leftJoin('products', 'order_items.item_id', '=', 'products.id')->select('order_items.*', 'products.name', 'products.picture')->get(); $items[$ord['id']] = $i->toArray(); } return View::make('user/show', array('addresses' => $addresses, 'orders' => $orders, 'items' => $items)); }
public function postAddress() { $v = Validator::make(Input::all(), ['address' => 'required|min:10']); if ($v->passes()) { $uid = Auth::user()->id; $orders = Orderitem::where('user_id', $uid)->where('status', 0)->get(); $neworder = new Order(); $neworder->address = Input::get('address'); $neworder->user_id = $uid; $neworder->save(); foreach ($orders as $order) { $order->status = 1; $order->order_id = $neworder->id; $order->save(); } return Redirect::to('/checkout/confirm'); } return Redirect::to('/checkout/address')->withInput()->withErrors($v)->with('message', 'There has been a problem while submitting your address'); }
public function __construct() { if (Auth::check()) { $this->beforeFilter(function () { $userid = Auth::user()->id; $orders = Orderitem::where('user_id', $userid)->where('status', 0); $total = 0; $items = $orders->get(); foreach ($items as $item) { $temp = $item->quantity * $item->price; $total = $total + $temp; } View::share('count', $orders->count()); View::share('orders', $orders->get()); View::share('total', $total); }); } $this->beforeFilter(function () { View::share('catnav', Category::all()); }); }