public function show($id)
 {
     $orderDetails = OrderProduct::where('order_id', $id)->get();
     $order = Order::find($id);
     $options = new Collection();
     foreach ($orderDetails as $detail) {
         if ($detail->options) {
             $values = explode(',', $detail->options);
             foreach ($values as $value) {
                 $options->add(OptionValue::find($value));
             }
         }
     }
     return view('site.showOrder', compact('orderDetails', 'order', 'options'));
 }
예제 #2
0
 public function admin()
 {
     $output = array();
     $i = 0;
     $orders = Order::all();
     foreach ($orders as $order) {
         $pivots = OrderProduct::where('order_id', $order->id)->get();
         foreach ($pivots as $pivot) {
             $prod = Product::findOrFail($pivot['product_id']);
             $output[$i]['order'] = $order;
             $p = ['prod' => $prod, 'count' => $pivot['count'], 'cost_all' => (int) $pivot['count'] * (int) $prod->cost];
             $output[$i]['product'][] = $p;
         }
         $i++;
     }
     return view('admin', ['data' => $output]);
 }
예제 #3
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $user = Auth::User();
     $cart = DB::table('orders')->select('id')->where('status_id', '=', 1)->where('user_id', '=', $user->id)->value('id');
     if (empty($cart)) {
         $order = new Order();
         $order->user_id = $user->id;
         $order->status_id = 1;
         $order->save();
         $orderProduct = new OrderProduct();
         $orderProduct->order_id = $order->id;
         $orderProduct->product_id = $request->product_id;
         $orderProduct->quantity = $request->quantity;
         $orderProduct->save();
     } else {
         // if you already have this product in your cart just add the next quantity to the same line item
         if (OrderProduct::where('order_id', $cart)->where('product_id', $request->product_id)->exists()) {
             $repeatOrderProduct = OrderProduct::where('order_id', $cart)->where('product_id', $request->product_id)->first();
             $orderProduct = OrderProduct::find($repeatOrderProduct->id);
             $orderProduct->product_id = $request->product_id;
             $orderProduct->quantity = $request->quantity + $orderProduct->quantity;
             $orderProduct->save();
         } else {
             $orderProduct = new OrderProduct();
             $orderProduct->order_id = $cart;
             $orderProduct->product_id = $request->product_id;
             $orderProduct->quantity = $request->quantity;
             $orderProduct->save();
         }
     }
     Activity::log('Saved an item to their cart.', $user->id);
     $request->session()->flash('status', 'Product was saved to cart.');
     return Redirect::action('CartController@index');
 }