public function editProduct($id) { // $product = Products::findOrFail($id); $options = Options::all(); $opt_arr = []; foreach ($options as $key => $value) { $opt_arr[$value->id] = $value->name; } $myopt = $product->productOptions; //dd($myopt->pivot->option_id); $myopt_arr = []; foreach ($myopt as $key => $value) { //$myprods_arr[] = $value->id; array_push($myopt_arr, $value->pivot->option_id); } //dd($product->recommendProd); $myprod = $product->recommendProd; $myprods_arr = []; foreach ($myprod as $key => $value) { //$myprods_arr[] = $value->id; array_push($myprods_arr, $value->product_id_recommend); } $cats = Categories::orderBy('sort_id', 'asc')->get(); $prods = Products::orderBy('sort_id', 'asc')->get(); $cats_arr = []; foreach ($cats as $key => $value) { $cats_arr[$value->id] = $value->name; } $prods_arr = []; foreach ($prods as $key => $value) { $prods_arr[$value->id] = $value->name; } //dd($prods_arr); $product->isset == 'false' ? $product->isset = Null : $product->isset; //dd($product->isset); $data = ['CatList' => $cats_arr, 'Prods' => $prods_arr, 'myProds' => $myprods_arr, 'product' => $product, 'NewOrderCounter' => Purchase::Neworders()->count(), 'opt_arr' => $opt_arr, 'myopt_arr' => $myopt_arr]; return view('admin.content.productEdit')->with($data); }
/** * Show the form for editing the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function edit($id) { // $order = Purchase::findOrFail($id); $totalCount = 0; $totalSumm = 0; foreach ($order->items as $item) { /* if (!in_array($item->product_id, ['np','fast', 'gift'])) { $totalCount=$totalCount+$item->qty; $totalSumm=$totalSumm+($item->product->price*$item->qty); }*/ if ($item->product_id == 'np') { $totalSumm = $totalSumm + Setting::get('product.np'); } else { if ($item->product_id == 'fast') { $totalSumm = $totalSumm + Setting::get('product.fast'); } else { if ($item->product_id == 'gift') { $totalSumm = $totalSumm + Setting::get('product.gift') * $item->qty; } else { if (strpos($item->product_id, '0000')) { //dd('consist'); $pID = explode('0000', $item->product_id); $option = Options::findOrFail($pID[1]); $product = Products::findOrFail($pID[0]); $productPrice = $option->price; $item->productPrice = $productPrice; $item->productName = $product->name . ' (' . $option->name . ')'; $item->productCover = $product->cover; $item->productUrlhash = $product->urlhash; } else { $productPrice = $item->product->price; $item->productPrice = $item->product->price; $item->productName = $item->product->name; $item->productCover = $item->product->cover; $item->productUrlhash = $item->product->urlhash; } $totalCount = $totalCount + $item->qty; $totalSumm = $totalSumm + $item->productPrice * $item->qty; } } } } $dNP = true; $dADR = false; if ($order->items()->where('product_id', 'np')->exists()) { $dNP = false; $dADR = true; } $privat24 = false; $privat_terminal = false; $liqpay = false; switch ($order->pay_type) { case 'privat24': // code... $privat24 = true; break; case 'privat_terminal': // code... $privat_terminal = true; break; case 'liqpay': // code... $liqpay = true; break; default: // code... break; } $prods = Products::all(); $prods_arr = []; foreach ($prods as $key => $value) { $prods_arr[$value->id] = $value->name; } $options = Options::all(); $opt_arr = []; $opt_arr[0] = 'Нет'; foreach ($options as $key => $value) { $opt_arr[$value->id] = $value->name; } $data = ['Options' => $opt_arr, 'order' => $order, 'totalCount' => $totalCount, 'totalSumm' => $totalSumm, 'dNP' => $dNP, 'dADR' => $dADR, 'Prods' => $prods_arr, 'privat24' => $privat24, 'privat_terminal' => $privat_terminal, 'liqpay' => $liqpay, 'NewOrderCounter' => Purchase::Neworders()->count()]; return view('admin.orderEdit')->with($data); }