public static function reFormatCartList() { $collection = []; foreach (Cart::getInstance()->getCartsList() as $product) { $collection[] = new self(['productid' => $product->id, 'price' => $product->price]); } return $collection; }
public function makeOrder(DeliveryRequest $request) { $this->validate($request); $orders = new Order(); $orders->address = $request->input('address'); $orders->contact = $request->input('contact'); $orders->phone = $request->input('phone'); $orders->email = $request->input('email'); $orders->sendwhen = null; $orders->created = date('Y-m-d H:i:s'); $orders->additional = $request->input('additional'); $orders->status = Order::STATUS['NEW']; $orders->totalprice = \App\Components\Cart::getInstance()->getTotalPrice(); $orders->save(); $request->except('_token'); $inserted = Order::find($orders->id); $inserted->products()->saveMany(Orderproducts::reFormatCartList()); Cart::getInstance()->clearAll(); return redirect('categories/all'); }
public function placeToCart($id) { $product = Product::find($id); Cart::getInstance()->addToCart($product); return redirect('products/product/' . $id); }