private function _getProductBySlug($slug) { $slugAttribute = ProductAttribute::where('identifier', '=', 'slug')->get()->first(); $productVarcharValue = ProductVarcharValue::where('product_attribute_id', '=', $slugAttribute->id)->where('value', '=', $slug)->where('website_id', '=', $this->websiteId)->get()->first(); $product = Product::findorfail($productVarcharValue->product_id); return $product; }
public function addToCart(Request $request, $id) { $cart = Session::get('cart'); $product = Product::findorfail($id); if (null !== $request->get('qty') && !isset($cart[$id])) { $cart[$id] = ['id' => $id, 'qty' => $request->get('qty'), 'price' => $product->price, 'tax_amount' => $product->getTaxAmount(), 'model' => $product]; } elseif (null !== $request->get('qty') && isset($cart[$id])) { $cart[$id]['qty'] += $request->get('qty'); } elseif (null === $request->get('qty') && isset($cart[$id])) { $cart[$id]['qty'] += 1; } else { $cart[$id] = ['id' => $id, 'qty' => 1, 'price' => $product->price, 'tax_amount' => $product->getTaxAmount(), 'model' => $product]; } Session::put('cart', $cart); return redirect()->back()->with('notificationText', 'Product Added to Cart Successfully!'); }
/** * Update the specified resource in storage. * * @param \\App\Http\Requests\ProductRequest $request * @param int $id * * @return \Illuminate\Http\Response */ public function update(ProductRequest $request, $id) { try { $product = Product::findorfail($id); $this->productHelper->saveProduct($product, $request); $this->productHelper->saveRelatedProducts($product, $request); $this->productHelper->saveCategory($product, $request); $this->productHelper->saveProductImages($product, $request); $this->productHelper->saveProductAttribute($product, $request); } catch (\Exception $e) { throw new \Exception('Error in Saving Product: ' . $e->getMessage()); } return redirect()->route('admin.product.index'); }