/** * Display the specified resource. * * @param int $id * @return Response */ public function show($id, ProductRepositoryInterface $productFromRepository) { try { $product = Product::with(['price', 'price.stantion'])->where('id', $id)->first(); } catch (ModelNotFoundException $e) { abort(404); } if (!$product) { abort(404); } if ($product->category_id) { $productParams = $productFromRepository->getProductProperties($id, true); } else { $productParams = $productFromRepository->getProductProperties($id, false); } $prices = $product->price; $pricesArr = []; foreach ($prices as $price) { $pricesArr[$price->stantion[0]->train_road->tr_name][] = ['stantion_name' => $price->stantion[0]->stantion_name, 'price' => $price->price, 'amount' => $price->amount, 'nds' => Product::getAllVAT_rateByKey($price->nds)]; } unset($prices); return view('products.show', ['productParams' => $productParams, 'prices' => $pricesArr, 'product' => $product]); }
public function showTrainCarProduct($id, $depoId, ProductRepositoryInterface $productFromRepository, ProductCart $cart) { try { $product = Product::with(['price', 'price.stantion'])->where('id', $id)->first(); } catch (ModelNotFoundException $e) { abort(404); } if (!$product) { abort(404); } if ($product->category_id) { $productParams = $productFromRepository->getProductProperties($id, true); } else { $productParams = $productFromRepository->getProductProperties($id, false); } $prices = $product->price; $pricesArr = []; foreach ($prices as $price) { if ($price->price > 0 && $price->amount > 0) { $pricesArr[$price->stantion[0]->train_road->tr_name][] = ['stantion_name' => $price->stantion[0]->stantion_name, 'stantion_id' => $price->stantion[0]->id, 'price_id' => $price->id, 'product_id' => $product->id, 'price' => $price->price, 'amount' => $price->amount]; } } unset($prices); if (Auth::guest()) { $userID = 0; } else { $userID = Auth::user()->id; } $sumAndCount = $this->getGeneralViewOfCart($cart); return view('purchases.showTrainCarProduct', ['p' => 'purchases', 'depoId' => $depoId, 'productParams' => $productParams, 'prices' => $pricesArr, 'product' => $product, 'userID' => $userID, 'productsCount' => $sumAndCount['productsCount'], 'productsSum' => $sumAndCount['productsSum']]); }