public function place(Order $orderModel, OrderItem $ordemItemMobel, CheckoutService $checkoutService) { $categories = Category::all(); if (!Session::has('cart')) { return false; } $cart = Session::get('cart'); if ($cart->getTotal() > 0) { $checkout = $checkoutService->createCheckoutBuilder(); $order = $orderModel->create(['user_id' => Auth::User()->id, 'total' => $cart->getTotal(), 'status_id' => 1]); $checkout->setReference($order->id); foreach ($cart->all() as $k => $item) { $checkout->addItem(new Item($k, $item['name'], number_format($item['price'], 2, '.', ''), $item['qtd'])); $order->items()->create(['product_id' => $k, 'price' => $item['price'], 'qtd' => $item['qtd']]); } $cart->clear(); event(new CheckoutEvent(Auth::user(), $order)); $response = $checkoutService->checkout($checkout->getCheckout()); return redirect($response->getRedirectionUrl()); } return view('store.checkout', ['order' => 'empty', 'categories' => $categories]); }
public function product($id, Category $category, Product $product) { $categories = $category->all(); $product = $product->find($id); return view('store.product', compact('categories', 'product')); }
/** * Show all products by tag. * * @param $id * @return \Illuminate\View\View */ public function tag($id) { $categories = Category::all(); $tag = Tag::find($id); return view('store.tag', compact('categories', 'tag')); }
/** * Show the form for editing the specified resource. * * @param int $id * @return Response */ public function edit($id, Category $category) { $product = $this->productModel->find($id); $categories = $category->lists('name', 'id'); return view('products.edit', compact('product', 'categories')); }