public function index() { $panel = ['center' => ['width' => 10], 'left' => ['width' => 2, 'class' => 'home-no-padding']]; $helperProd = new productsHelper(); $carousel = $helperProd->suggest('carousel'); $viewed = $helperProd->suggest('viewed', 8); $categories = $helperProd->suggest('categories'); $purchased = $helperProd->suggest('purchased'); $suggestion = ['carousel' => $carousel, 'viewed' => $viewed, 'categories' => $categories, 'purchased' => $purchased]; $helperProd->resetHaystack(); //reseting session id validator $events = []; if (config('app.offering_free_products')) { $events = FreeProduct::getNextEvents(['id', 'description', 'min_participants', 'max_participants', 'participation_cost', 'start_date', 'end_date'], 4, date('Y-m-d')); } $tagsCloud = ProductsController::getTopRated(0, 20, true); $allWishes = ''; $user = \Auth::user(); if ($user) { $allWishes = Order::ofType('wishlist')->where('user_id', $user->id)->where('description', '<>', '')->get(); } $i = 0; //carousel implementation $jumbotronClasses = ['jumbotron-box-left', 'jumbotron-box-right']; //carousel implementation $banner = ['/img/banner/01.png', '/img/banner/02.png', '/img/banner/03.png', '/img/banner/04.png']; // $this->createTags(); return view('home', compact('panel', 'suggestion', 'allWishes', 'events', 'tagsCloud', 'jumbotronClasses', 'i', 'banner')); }
/** * Display a listing of the resource. * * @return Response */ public function index(Request $request) { /** * $refine * array that contains all the information retrieved through the URL * array_unique is applied to avoid redundant variables. * * @var array */ $refine = \Utility::requestToArrayUnique($request->all()); /** * $search * this var contains the information typed into search box. * * @var [type] */ $search = $request->get('search'); /** * $products * Filtered products list. * * @var [type] */ $products = Product::select('id', 'category_id', 'name', 'price', 'description', 'condition', 'brand', 'rate_val', 'type', 'features', 'parent_id', 'tags')->search($search, false)->refine($refine)->free()->actives()->orderBy('rate_val', 'desc'); /** * $all_products * it is the product list refined, which will be used in each filter process below. * * @var [type] */ $all_products = $products->get(); /** * $suggestions * Array which contains the user product suggestions. * * @var array */ $suggestions = []; if (count($all_products) < 28) { $suggestions = productsHelper::suggest('my_searches'); } /* * $filters * it is the refine menu array, which is used to build the search options * @var [type] */ $category_id = $request->get('category') ? $request->get('category') : 'mothers'; $categories = \Cache::remember('categories_' . $category_id, 25, function () use($category_id) { return Category::select('id', 'name')->childsOf($category_id)->actives()->get()->toArray(); }); $filters = productsHelper::countingProductsByCategory($all_products, $categories); //condition $filters['conditions'] = array_count_values($all_products->lists('condition')->toArray()); //brand filter $filters['brands'] = array_count_values($all_products->lists('brand')->toArray()); //features $features = []; $irrelevant_features = ['images', 'dimensions', 'weight', 'brand']; //this has to be in company setting module foreach ($all_products->lists('features') as $feature) { $feature = array_except($feature, $irrelevant_features); foreach ($feature as $key => $value) { $features[$key][] = $value; } } //products by feature foreach ($features as $key => $value) { foreach ($features[$key] as $row) { if (!is_array($row)) { $filters[$key][$row] = !isset($filters[$key][$row]) ? 1 : $filters[$key][$row] + 1; } } } //prices filter $prices = $all_products->lists('price', 'price')->toArray(); sort($prices); //saving tags from searching products in users preferences if ($search != '') { $my_searches = []; $cont = 0; foreach ($all_products as $product) { if (trim($product->tags) != '') { $my_searches = array_merge($my_searches, explode(',', $product->tags)); } if ($cont++ == 10) { break; } } if (count($my_searches) > 0) { UserController::setPreferences('my_searches', $my_searches); } } $products = $products->paginate(28); $panel = $this->panel; $panel['left']['class'] = 'categories-panel'; $products->each(function (&$item) { if ($item['rate_count'] > 0) { $item['num_of_reviews'] = $item['rate_count'] . ' ' . \Lang::choice('store.review', $item['rate_count']); } }); return view('products.index', compact('filters', 'products', 'panel', 'listActual', 'search', 'refine', 'suggestions')); }