Exemple #1
0
 public function edit($id)
 {
     if (Request::isMethod('post')) {
         $rules = array('status_id' => 'required');
         $validator = Validator::make(Input::all(), $rules);
         if ($validator->fails()) {
             return Redirect::to("admin/{$this->name}/{$id}/{$this->action}")->withErrors($validator)->withInput(Input::except(''));
         } else {
             $table = Order::find($id);
             $table->status_id = Input::get('status_id');
             if ($table->save()) {
                 $name = trans("name.{$this->name}");
                 return Redirect::to("admin/{$this->name}")->with('success', trans("message.{$this->action}", ['name' => $name]));
             }
             return Redirect::to("admin/{$this->name}")->with('error', trans('message.error'));
         }
     }
     $order = DB::table('orders as o')->join('users as u', 'o.user_id', '=', 'u.id')->join('order_status as os', 'o.status_id', '=', 'os.id')->join('orders_details as od', 'o.id', '=', 'od.order_id')->select('o.id', DB::raw('CONCAT(u.firstname, " ", u.lastname) AS fullname'), 'os.title', 'o.created_at', DB::raw('SUM(od.price) AS total'), 'o.comment', 'o.status_id')->where('o.id', $id)->first();
     $products = DB::table('products as p')->join('orders_details as od', 'p.id', '=', 'od.product_id')->join('orders as o', 'od.order_id', '=', 'o.id')->select('p.id', 'p.link', 'p.name', 'od.price', 'od.quantity', DB::raw('od.price * od.quantity AS total'))->where('o.id', $id)->orderBy('o.id', 'asc')->get();
     $ordersStatus = OrderStatus::all();
     foreach ($ordersStatus as $status) {
         $orderStatus[$status['id']] = $status['title'];
     }
     return View::make("admin.shop.order.edit", ['item' => $order, 'name' => $this->name, 'action' => $this->action, 'status' => $orderStatus, 'products' => $products]);
 }
 public static function init()
 {
     self::$FINISHED = new OrderStatus("FINISHED");
     self::$PENDING = new OrderStatus("PENDING");
     self::$CANCELLED = new OrderStatus("CANCELLED");
     self::$NEW = new OrderStatus("NEW");
     self::$CONFIRMED = new OrderStatus("CONFIRMED");
     //		self::$HOLD = new OrderStatus("HOLD");
     self::$TRASH = new OrderStatus("TRASH");
     self::$REBOOK = new OrderStatus("REBOOK");
     //static map to get object by name - example Enum::get("INIT") - returns Enum::$INIT object;
     self::$all = array(self::$PENDING, self::$CONFIRMED, self::$CANCELLED, self::$TRASH, self::$REBOOK);
     self::$map = array(self::$PENDING, self::$CONFIRMED, self::$CANCELLED);
 }