public function index() { // Visitor::log(); $cats = Categories::orderBy('sort_id', 'asc')->get(); $products = Products::orderBy('sort_id', 'asc')->get(); Setting::get('config.mainprod', Null) ? $mainProdImg = asset('/files/img/' . Setting::get('config.mainprod')) : ($mainProdImg = asset('dist/img/photo4.jpg')); Setting::get('config.logo', Null) ? $logoMain = asset('/files/img/' . Setting::get('config.logo')) : ($logoMain = asset('dist/img/logo.png')); $topProds = DB::table('order_items')->select('product_id', DB::raw('count(*) as total'))->groupBy('product_id')->orderBy('total', 'desc')->take('5')->get(); $topProdsArr = []; foreach ($topProds as $topprod) { if (!in_array($topprod->product_id, ['fast', 'np', 'gift'])) { if (strpos($topprod->product_id, '0000')) { //dd('consist'); $pID = explode('0000', $topprod->product_id); //$topprod->product_id = $pID[0]; $prodID = $pID[0]; } else { $prodID = $topprod->product_id; } $prodName = Products::findOrFail($prodID); //echo $prodName->name; array_push($topProdsArr, ['name' => $prodName->name, 'cover' => $prodName->cover, 'link' => $prodName->urlhash]); } // code... } //dd(collect($topProdsArr)); $data = ['cats' => $cats, 'products' => $products, 'PageDescr' => Setting::get('config.maindesc'), 'PageWords' => Setting::get('config.mainwords'), 'PageAuthor' => '', 'PageTitle' => Setting::get('config.maintitle'), 'mainProdImg' => $mainProdImg, 'logoMain' => $logoMain, 'topProds' => $topProdsArr, 'totalNavLabel' => $this->totalNavLabel()]; return view('catalogPage')->with($data); }
public function ShortLinkCategory($id) { Visitor::log(); $cat = Categories::whereUrlhash($id)->firstorfail(); $cats = Categories::orderBy('sort_id', 'asc')->get(); // Setting::get('config.mainprod', Null) ? $mainProdImg = asset('/files/img/' . Setting::get('config.mainprod')) : ($mainProdImg = asset('dist/img/photo4.jpg')); Setting::get('config.logo', Null) ? $logoMain = asset('/files/img/' . Setting::get('config.logo')) : ($logoMain = asset('dist/img/logo.png')); $topProds = DB::table('order_items')->select('product_id', DB::raw('count(*) as total'))->groupBy('product_id')->orderBy('total', 'desc')->take('5')->get(); $topProdsArr = []; foreach ($topProds as $topprod) { if (!in_array($topprod->product_id, ['fast', 'np', 'gift'])) { $prodName = Products::findOrFail($topprod->product_id); //echo $prodName->name; array_push($topProdsArr, ['name' => $prodName->name, 'cover' => $prodName->cover, 'link' => $prodName->urlhash]); } // code... } $products = Products::orderBy('sort_id', 'asc')->whereCategories_id($cat->id)->get(); //dd($products ); $data = ['cats' => $cats, 'products' => $products, 'PageDescr' => Setting::get('config.maindesc'), 'PageWords' => Setting::get('config.mainwords'), 'PageAuthor' => '', 'PageTitle' => Setting::get('config.maintitle') . ' - ' . $cat->name, 'mainProdImg' => $mainProdImg, 'logoMain' => $logoMain, 'topProds' => $topProdsArr, 'category' => $cat, 'totalNavLabel' => $this->totalNavLabel()]; return view('catalogPageOne')->with($data); }
public function destroyProduct(Request $request, $id) { $prod = Products::findOrFail($id); if (isset($prod->cover)) { File::delete('files/cats/img/' . $prod->cover); File::delete('files/cats/img/small/' . $prod->cover); } $prod->delete(); //$request->session()->flash('alert-success', 'Категория успешно удалена!'); //return redirect('content/cat'); }
/** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { // $clients = Clients::all(); $purchase = Purchase::all(); $products = Products::all(); //$orders=Purchase::all(); $ordersLim = Purchase::orderBy('id', 'desc')->take(5)->get(); foreach ($ordersLim as $order) { if ($order->status == 'paid') { $order->rowStyle = 'warning'; } else { if ($order->status == 'sent') { $order->rowStyle = 'success'; } else { $order->rowStyle = ''; } } $ordertotalCount = 0; $ordertotalSumm = 0; $itemFast = false; $itemGift = false; foreach ($order->items as $item) { if ($item->product_id == 'np') { $ordertotalSumm = $ordertotalSumm + Setting::get('product.np'); } else { if ($item->product_id == 'fast') { $itemFast = true; $ordertotalSumm = $ordertotalSumm + Setting::get('product.fast'); } else { if ($item->product_id == 'gift') { $itemGift = true; $ordertotalSumm = $ordertotalSumm + 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; } $ordertotalCount = $ordertotalCount + $item->qty; $ordertotalSumm = $ordertotalSumm + $item->productPrice * $item->qty; } } } } $order->itemFast = $itemFast; $order->itemGift = $itemGift; $order->totalCount = $ordertotalCount; $order->totalSumm = $ordertotalSumm; } //dd($order->totalSumm); $orders = Purchase::where('status', 'sent')->get(); $totalSumm = 0; $totalCount = 0; foreach ($orders as $order) { foreach ($order->items as $item) { 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; } } } } } $topProds = DB::table('order_items')->select('product_id', DB::raw('count(*) as total'))->groupBy('product_id')->orderBy('total', 'desc')->take('5')->get(); $topProdsArr = []; //dd($topProds); foreach ($topProds as $topprod) { if (!in_array($topprod->product_id, ['fast', 'np', 'gift'])) { if (strpos($topprod->product_id, '0000')) { //dd('consist'); $pID = explode('0000', $topprod->product_id); //$topprod->product_id = $pID[0]; $prodID = $pID[0]; } else { $prodID = $topprod->product_id; } $prodName = Products::findOrFail($prodID); //echo $prodName->name; array_push($topProdsArr, ['name' => $prodName->name, 'urlhash' => $prodName->urlhash, 'qty' => $topprod->total]); // code... } } /*OrderItems::whereNotIn('product_id', ['np','fast','gift']) ->orderBy('qty') ->groupBy('product_id') ->get();*/ //dd($topProdsArr); //$NewOrderCounter=Purchase::Neworders()->count(); $data = ['totalClients' => $clients->count(), 'totalPurchase' => $purchase->count(), 'totalPurchaseOk' => $purchase->where('status', 'sent')->count(), 'totalProducts' => $products->count(), 'totalMoney' => $totalSumm, 'totalCount' => $totalCount, 'orders' => $ordersLim, 'topProds' => $topProdsArr, 'NewOrderCounter' => Purchase::Neworders()->count()]; return view('admin.dashboard')->with($data); }
public function storeProduct(Request $request, $id) { // $product = Products::findOrFail($id); //Cart::add('293ad', 'Product 1', 1, 9.99, array('size' => 'large')); //dd($prod_arr); //$cartEl=Cart::search(['id' => intval($product->id)]); //dd($cartEl); //Cart::destroy(); Cart::add(intval($product->id), $product->name, 1, intval($product->price), []); //Cart::add('192ao12', 'Product 1', 1, 9.99); //Cart::add('192ao12', 'Product 1', 1, 9.99); //$cart=Cart::content(); //dd($cart); // return dd(Cart::content()); }
/** * 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 { $totalCount = $totalCount + $item->qty; $totalSumm = $totalSumm + $item->product->price * $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; } $data = ['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); }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { // if (Cart::count() == 0) { $request->session()->flash('alert-danger', 'У Вас пустая корзина. Что бы оформить заказ, наполните её.'); return back()->withInput(); } //IF CART EMPTY //$request->session()->flash('alert-success', 'Конфигурация сохранена!'); //return view('orderConfirm')->with($data); $rules = ['name' => 'required|min:5|max:255', 'tel' => 'required|min:6|max:255', 'mail' => 'required|email']; $nbr = count(Input::file('files')) - 1; foreach (range(0, $nbr) as $index) { $rules['files.' . $index] = 'mimes:jpeg,bmp,png,pdf,psd|max:10000'; } //dd($rules); $validator = Validator::make(Input::all(), $rules); if ($validator->fails()) { //dd($validator); return back()->withErrors($validator)->withInput(); } else { $client = new Clients(); $client->name = $request->name; $client->email = $request->mail; $client->tel = $request->tel; $client->save(); $orderCode = strtoupper(str_random(5)); /*$fp=Purchase::whereCode($orderCode)->isset(); while ($orderCode != $fp->) { # code... }*/ //delivery_city_adr if ($request->delivery_type == 'np') { $city = NPCity::whereRef($request->delivery_city)->first(); } else { if ($request->delivery_type == 'adr') { $city = NPCity::whereRef($request->delivery_city_adr)->first(); } } $order = new Purchase(); $order->client_id = $client->id; $order->code = $orderCode; $order->delivery_type = $request->delivery_type; $order->delivery_city = $city->name; if ($request->delivery_type == 'np') { $order->delivery_np = $request->delivery_np; } if ($request->delivery_type == 'adr') { $order->delivery_adr = $request->delivery_adr; } $order->pay_type = $request->pay_type; $order->comment = $request->comment; $order->save(); $cart = Cart::content(); $itemArr = []; foreach ($cart as $value) { array_push($itemArr, ['order_id' => $order->id, 'product_id' => $value->id, 'qty' => $value->qty]); //echo $value->name; } //dd(null); OrderItems::insert($itemArr); $orderItems = OrderItems::whereOrder_id($order->id)->get(); //dd($orderItems); // new OrderItems; $order->delivery_type == 'np' ? $delivery_type = 'Склад Новая Почта' : ($delivery_type = 'Курьерская доставка по адресу'); //'nal','privat24','privat_terminal','liqpay' switch ($order->pay_type) { case 'nal': $pay_type = 'Наличными'; // code... break; case 'privat24': $pay_type = 'Privat24. Через онлайн-систему для владельцев карт ПриватБанка.'; // code... break; case 'privat_terminal': $pay_type = 'На карту. Через пополнение карты, например через терминал самообслуживания.'; //Через пополнение карты, например через терминал самообслуживания. // code... break; case 'liqpay': $pay_type = 'LiqPay. Через онлайн систему для владельце карт других банков. (+10% комиссия)'; // code... break; default: $pay_type = 'Не указано'; // code... break; } //COUNT QTY //COUNT SUMM $totalCount = $orderItems->sum('qty'); //$totalCount=$orderItems->sum('qty'); $totalSumm = 0; foreach ($orderItems as $value) { // code... if ($value->product_id == 'np') { $totalSumm = $totalSumm + Setting::get('product.np'); } else { if ($value->product_id == 'fast') { $totalSumm = $totalSumm + Setting::get('product.fast'); } else { if ($value->product_id == 'gift') { $totalSumm = $totalSumm + Setting::get('product.gift') * $value->qty; } else { //!strpos($a, 'are') if (strpos($value->product_id, '0000')) { //dd('consist'); $pID = explode('0000', $value->product_id); $option = Options::findOrFail($pID[1]); $product = Products::findOrFail($pID[0]); $productPrice = $option->price; $value->productPrice = $productPrice; $value->productName = $product->name . ' (' . $option->name . ')'; } else { $productPrice = $value->product->price; $value->productPrice = $value->product->price; $value->productName = $value->product->name; } //echo $value->qty."__"; $totalSumm = $totalSumm + $productPrice * $value->qty; } } } } Setting::get('config.logo', Null) ? $logoMain = asset('/files/img/' . Setting::get('config.logo')) : ($logoMain = asset('dist/img/logo.png')); $data = ['orderCode' => $orderCode, 'client' => $client, 'delivery_type' => $delivery_type, 'order' => $order, 'pay_type' => $pay_type, 'orderItems' => $orderItems, 'totalCount' => $totalCount, 'totalSumm' => $totalSumm, 'PageDescr' => Setting::get('config.maindesc'), 'PageWords' => Setting::get('config.mainwords'), 'PageAuthor' => '', 'PageTitle' => Setting::get('config.maintitle'), 'logoMain' => $logoMain, 'totalNavLabel' => $this->totalNavLabel(), 'appURL' => config('app.url')]; //dd($orderItems->toarray()); /* Mail::queue('mail.neworder', $data, function ($message) { $message->from('*****@*****.**', 'Larashop'); $message->subject('LaraShop'); $message->to('*****@*****.**'); }); */ if (!empty(Input::file('files')[0])) { $destinationPath = 'files/uploads/'; // upload path foreach ($request->file('files') as $file) { // code... $extension = $file->getClientOriginalExtension(); // getting image extension $mime = $file->getClientMimeType(); $originalName = $file->getClientOriginalName(); $hash = str_random(40); $fileName = $hash . '.' . $extension; // renameing image $file->move($destinationPath, $fileName); $isimage = 'false'; if (substr($mime, 0, 5) == 'image') { $isimage = 'true'; } $fileDB = OrderFiles::create(['order_id' => $order->id, 'name' => $originalName, 'hash' => $hash, 'mime' => $mime, 'extension' => $extension, 'status' => 'success', 'image' => $isimage]); } } //$DataMail=view('mail.neworder')->with($data)->render(); //dd($DataMail); Cart::destroy(); Mail::queue('mail.neworder', $data, function ($message) use($client) { $message->from(Setting::get('config.email'), Setting::get('config.sitename')); $message->subject(Setting::get('config.sitename') . ' - НОВЫЙ ЗАКАЗ'); $message->to($client['email']); }); Mail::queue('mail.neworder', $data, function ($message) use($client) { $message->from(Setting::get('config.email'), Setting::get('config.sitename')); $message->subject(Setting::get('config.sitename') . ' - НОВЫЙ ЗАКАЗ'); $message->to(Setting::get('config.email')); }); return view('orderConfirm')->with($data); } }
public function storeComment(Request $request, $id) { $product = Products::find($id); $validator = Validator::make($request->all(), ['name' => 'required|min:2|max:120', 'email' => 'required|email', 'msg' => 'required|min:5', 'captcha' => 'required|captcha']); if ($validator->fails()) { return redirect($product->urlhash . '.html#comment')->withErrors($validator)->withInput(); } else { $comment = new Comments(); $comment->name = $request->name; $comment->email = $request->email; $comment->msg = $request->msg; $comment->product_id = $product->id; $comment->save(); $request->session()->flash('alert-success', 'Комментарий отправлен и будет обработан после модерации!'); return redirect($product->urlhash . '.html#comment'); } }
public function storeProduct(Request $request, $id) { // //dd($request->opt); $product = Products::findOrFail($id); if ($request->opt != "Null") { $option = Options::findOrFail($request->opt); $product->name = $product->name . " (" . $option->name . ") "; $product->price = $option->price; $product->id = $product->id . "0000" . $option->id; } //Cart::add('293ad', 'Product 1', 1, 9.99, array('size' => 'large')); //dd($prod_arr); //$cartEl=Cart::search(['id' => intval($product->id)]); //dd($cartEl); //Cart::destroy(); Cart::add(intval($product->id), $product->name, 1, intval($product->price), []); //Cart::add('192ao12', 'Product 1', 1, 9.99); //Cart::add('192ao12', 'Product 1', 1, 9.99); //$cart=Cart::content(); //dd($cart); // return dd(Cart::content()); }
/** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function showPrint($id) { $order = Purchase::findOrFail($id); $order->delivery_np == 'np' ? $delivery_type = 'Склад Новая Почта' : ($delivery_type = 'Курьерская доставка по адресу'); //'nal','privat24','privat_terminal','liqpay' switch ($order->pay_type) { case 'nal': $pay_type = 'Наличными'; // code... break; case 'privat24': $pay_type = 'Privat24. Через онлайн-систему для владельцев карт ПриватБанка.'; // code... break; case 'privat_terminal': $pay_type = 'На карту. Через пополнение карты, например через терминал самообслуживания.'; //Через пополнение карты, например через терминал самообслуживания. // code... break; case 'liqpay': $pay_type = 'LiqPay. Через онлайн систему для владельце карт других банков. (+10% комиссия)'; // code... break; default: $pay_type = 'Не указано'; // code... break; } $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; } } } } if ($order->status == 'paid') { $pay_status = 'Оплачено, ожидает отправку.'; } else { if ($order->status == 'sent') { $pay_status = 'Отправлено получателю.'; } else { $pay_status = 'Новый заказ, ожидает оплату.'; } } $data = ['order' => $order, 'delivery_type' => $delivery_type, 'pay_type' => $pay_type, 'pay_status' => $pay_status, 'totalCount' => $totalCount, 'totalSumm' => $totalSumm]; return view('admin.orderPrint')->with($data); }