![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/mcoil.corals.io/app/Http/Controllers/Front/ |
<?php namespace App\Http\Controllers\Front; use App\Shop\Products\Product; use App\Shop\Products\Repositories\Interfaces\ProductRepositoryInterface; use App\Http\Controllers\Controller; use App\Shop\Products\Transformations\ProductTransformable; use App\Shop\VatDisplaySettings\VatDisplaySetting; use Illuminate\Support\Facades\DB; use App\Shop\Pages\Creator; use App\Shop\Banners\Banner; use App\Shop\VideoTextBoxes\VideoTextBox; use App\Shop\TextBoxes\TextBox; use App\Shop\Categories\Category; use App\Shop\ServiceBoxes\ServiceBox; use App\Shop\CalltoAction\CalltoAction; class ProductController extends Controller { use ProductTransformable; /** * @var ProductRepositoryInterface */ private $productRepo; /** * ProductController constructor. * @param ProductRepositoryInterface $productRepository */ public function __construct(ProductRepositoryInterface $productRepository) { $this->productRepo = $productRepository; } /** * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View */ public function search() { /*if (request()->has('q') && request()->input('q') != '') { $list = $this->productRepo->searchProduct(request()->input('q')); } else { // Get the list of popular products $popularProductList = $this->productRepo->listProducts('product_view_count', 'desc'); }*/ /*$popularProducts = $popularProductList->where('status', 1) ->where('oil_type_status', 0) // We have to show only front-end listing products here ->map(function (Product $item) { return $this->transformProduct($item); });*/ /**** Get the listing of best seller products ****/ // Get the list of ordered products /*$orderProducts = DB::table('products') ->join('order_product', 'order_product.product_id', '=', 'products.id') ->where('products.status', '=', '1') ->where('products.oil_type_status', '=', '0') ->select(['product_id', DB::raw("SUM(order_product.quantity) as quantity")]) ->groupBy('product_id') ->get(); $orderedProducts = array(); if( $orderProducts ) { foreach( $orderProducts as $orderProduct ) { $orderedProducts[] = $orderProduct->product_id; } }*/ // Get the frequently purchased product // $purchasedProducts = $this->productRepo->purchasedProducts($orderedProducts); // Get the non purchased product // $nonPurchasedProducts = $this->productRepo->nonPurchasedProducts($orderedProducts); // Merge them // $bestSellerProducts = $purchasedProducts->merge($nonPurchasedProducts); /**** Get the listing of best seller products ends ****/ // Get the query string (if available) and store it to show the selected tab $page_details = Creator::where('slug', 'products')->first(); if($page_details){ $textBox1 = null; $modules = json_decode($page_details->modules); $banner1 = null; if($modules->banner1){ $banner1 = Banner::find($modules->banner1); } $banner2 = null; if($modules->banner2){ $banner2 = Banner::find($modules->banner2); } $textBox1 =null; if($modules->text_box1){ $textBox1 = TextBox::find($modules->text_box1); } $textBox2 = null; if($modules->text_box2){ $textBox2 = TextBox::find($modules->text_box2); } $productServiceBoxes = null; if(isset($modules->service_box1)) { $productService = ServiceBox::find($modules->service_box1); if ($productService) { $productServiceBoxes = ServiceBox::where('type', $productService->type)->orderBy('orderNO','ASC')->take($page_details->no_of_service_box_display)->get(); } } $orderStepServiceBoxes = null; if(isset($modules->service_box2)){ $orderStepService = ServiceBox::find($modules->service_box2); if ($orderStepService) { $orderStepServiceBoxes = ServiceBox::where('type', $orderStepService->type)->orderBy('orderNO','ASC')->take($page_details->no_of_service_box_display2)->get(); } } $calltoaction = null; if($modules->call_to_action){ $calltoaction = CalltoAction::find($modules->call_to_action); } } $selectedTab = ''; if (request()->has('popular_products') && request()->input('popular_products') != '') { $selectedTab = 'popular_products'; } else if (request()->has('best_seller_products') && request()->input('best_seller_products') != '') { $selectedTab = 'best_seller_products'; } // Get the no of products to be listed $productDisplayCount = DB::table('product_display_counts')->where(['id' => 1])->first(); $displayCount = 10; // Default value is 10 if( $productDisplayCount ) { $displayCount = $productDisplayCount->display_count; } // Get the featured categories $featuredCategories = DB::table('categories') ->where(['featured_category' => '1', 'status' => 1]) ->whereNotNull('featured_category_sequence') ->orderBy('featured_category_sequence') ->limit(3) ->get(); if( $featuredCategories ) { $featuredCategories = $featuredCategories->toArray(); } $search =0; // Get the popular products if (request()->has('q') && request()->input('q') != '') { $searchText = request()->input('q'); $popularProducts = Product::where(['oil_type_status' => '0', 'status' => 1]) //->where('name', '=', request()->input('q')) ->where(function($query) use($searchText){ $query->where('name','Like','%'.$searchText.'%') ->orWhere('sku','Like','%'.$searchText.'%'); }) ->orderBy('product_view_count', 'asc') ->paginate($displayCount, ['*'], 'popular_products'); $featuredCategories =null; $search =1; } else { $popularProducts = Product::where(['oil_type_status' => '0', 'status' => 1]) ->orderBy('product_view_count', 'asc') ->paginate($displayCount, ['*'], 'popular_products'); } // Get the best seller products if (request()->has('q') && request()->input('q') != '') { // $bestSellerProducts = Product::leftJoin('order_product', 'products.id', 'order_product.product_id') // ->where(['products.oil_type_status' => '0', 'products.status' => 1]) // ->where(function($query) use($searchText){ // $query->where('products.name','Like','%'.$searchText.'%') // ->orWhere('sku','Like','%'.$searchText.'%'); // }) // ->select('products.*') // ->groupBy('products.id') // ->orderBy('order_product.quantity', 'desc') // ->paginate($displayCount, ['*'], 'best_seller_products'); $bestSellerProducts = null; } else { $bestSellerProducts = Product::leftJoin('order_product', 'products.id', 'order_product.product_id') ->where(['products.oil_type_status' => '0', 'products.status' => 1]) ->select('products.*') ->groupBy('products.id') ->orderBy('order_product.quantity', 'desc') ->paginate($displayCount, ['*'], 'best_seller_products'); } // Vat display setting $vatDisplaySetting = VatDisplaySetting::first(); return view('front.products.product-search', [ // 'products' => $this->productRepo->paginateArrayResults($products->all(), 10) 'featuredCategories' => $featuredCategories, 'selectedTab' => $selectedTab, // Old one // 'popularProducts' => $this->productRepo->paginateArrayResults($popularProducts->all(), $displayCount), // 'bestSellerProducts' => $this->productRepo->paginateArrayResults($bestSellerProducts->all(), $displayCount), // New 'popularProducts' => $popularProducts, 'bestSellerProducts' => $bestSellerProducts, 'vatDisplaySetting' => $vatDisplaySetting, 'is_search' => $search, 'page_details' => $page_details, 'banner1' => $banner1, 'banner2' => $banner2, 'textBox1' => $textBox1, 'textBox2' => $textBox2, 'productServiceBoxes' => $productServiceBoxes, 'orderStepServiceBoxes' => $orderStepServiceBoxes, 'calltoaction' => $calltoaction ]); } /** * Get the product * * @param string $category * @param string $slug * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View */ public function show(string $category, string $slug) { $product_data = Product::where('slug',$slug)->first(); if($product_data){ $product = $this->productRepo->findProductBySlug(['slug' => $slug]); if($product->oil_type_status != 1){ $images = $product->images()->get(); $category = $product->categories()->first(); $productAttributes = $product->attributes; // Update the product view Product::where('slug',$slug)->update(['product_view_count'=> DB::raw('product_view_count + 1')]); // Get some random products $similarProducts = Product::inRandomOrder() ->where(['oil_type_status' => '0', 'status' => 1]) ->orderBy('product_view_count', 'asc') ->limit(8) ->get(); // To manage some jquery files to be attached for specific page only $isProductDetailPage = true; // Vat display setting $vatDisplaySetting = VatDisplaySetting::first(); return view('front.products.product', compact( 'product', 'images', 'productAttributes', 'category', 'similarProducts', 'isProductDetailPage', 'vatDisplaySetting' )); }else{ return redirect('404'); } }else{ return redirect('404'); } // $product = $this->productRepo->findProductBySlug(['slug' => $slug]); // $images = $product->images()->get(); // $category = $product->categories()->first(); // $productAttributes = $product->attributes; // return view('front.products.product', compact( // 'product', // 'images', // 'productAttributes', // 'category' // )); } public function searchProduct(){ } }