Example #1
0
 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'));
 }
Example #2
0
 /**
  * Show the contents of a wish list
  *
  * @return view for orders.wish
  */
 public function showWishList($id = '')
 {
     /**
      * Checking if there is a product in flashWishList, if so, it will be saved into the basic wish list.
      * This process happens just before the user add a product to wishlist being not logged.
      * flashWishList will be deleted after being used into addToOrder method
      */
     if (Session::get('flashWishList') !== null) {
         $this->addToOrder('wishlist', Session::get('flashWishList.productId'), new Request());
         Session::forget('flashWishList');
         Session::save();
     }
     //saving added to wishlist message (it happens when the product is added to wishlist, and the method call this one)
     Session::forget('suggest-listed');
     if (Session::has('message')) {
         Session::push('message', Session::get('message'));
     }
     $user = \Auth::user();
     $productsHelper = new productsHelper();
     $suggestions = [];
     $hasWishList = true;
     $hasLaterCart = true;
     $wishListName = trans('store.basic_wish_list');
     if ($user) {
         /**
          * it is used to verify whether the order required exist or not.
          * if the order exists, its content is returned, otherwise,
          * the basic wish list is retrieved
          * @var string
          */
         $order = '';
         /**
          * validating if there's a order requested.
          * if it fails, there will be an 404 exception threw
          */
         try {
             $order = Order::findOrFail($id);
         } catch (ModelNotFoundException $e) {
             if (trim($id) != '') {
                 throw new NotFoundHttpException();
             }
         }
         //if the user requires a specific wish list, its details will be provided
         if ($order) {
             $cart = Order::ofType('wishlist')->with('details')->where('user_id', $user->id)->where('id', $order->id)->first();
             /**
              * $wishListName will have the wish list name to be showed in the view
              * @var string
              */
             $wishListName = $cart ? $cart->description : $wishListName;
         } else {
             $cart = Order::ofType('wishlist')->with('details')->where('user_id', $user->id)->first();
         }
         /**
          * listing the user wish lists saved in his account.
          * if there was a specific wish list requiered, it will be excluded from the directory list
          */
         $wishLists = Order::select(['id', 'user_id', 'description'])->ofType('wishlist')->with('details')->where('description', '<>', '')->where('user_id', $user->id)->where('id', '<>', $cart ? $cart->id : '')->take(5)->get();
         //products list saved for later
         $laterCart = Order::ofType('later')->with('details')->where('user_id', $user->id)->first();
         //evaluating wish list
         if ($cart) {
             if ($cart->details && $cart->details->count() > 0) {
                 //saving the ids selected to not include them into suggestions.
                 $productsHelper->setToHaystack($cart->details, 'product_id');
             } else {
                 $hasWishList = false;
             }
         } else {
             $hasWishList = false;
         }
         //evaluating wish list
         if ($laterCart) {
             if ($laterCart->details && $laterCart->details->count() > 0) {
                 //saving the ids selected to not include them into suggestions.
                 $productsHelper->setToHaystack($laterCart->details, 'product_id');
             } else {
                 $hasLaterCart = false;
             }
         } else {
             $hasLaterCart = false;
         }
     } else {
         return redirect()->route('/auth/login');
     }
     $panel = ['center' => ['width' => '12']];
     //suggestions based on cart content
     $suggestions = ProductsController::getSuggestions(['preferences_key' => Session::get('suggest-listed'), 'limit' => 4]);
     Session::forget('suggest-listed');
     return view('orders.wish', compact('cart', 'user', 'panel', 'suggestions', 'cart', 'laterCart', 'wishLists', 'wishListName', 'hasWishList', 'hasLaterCart'));
 }
 /**
  * Show the form for editing the specified resource.
  *
  * @param int $id
  *
  * @return Response
  */
 public function edit($id)
 {
     $product = Product::find($id);
     if (\Auth::id() != $product->user_id) {
         return redirect('products/' . $product->user_id)->withErrors(['not_access' => [trans('globals.not_access')]]);
     }
     $typeItem = $product->type;
     $disabled = '';
     $order = OrderDetail::where('product_id', $id)->join('orders', 'order_details.order_id', '=', 'orders.id')->first();
     if ($order) {
         $disabled = 'disabled';
     }
     $features = ProductDetail::all()->toArray();
     $allCategoriesStore = Category::actives()->lightSelection()->get()->toArray();
     $categories = ['' => trans('product.controller.select_category')];
     //categories drop down formatted
     productsHelper::categoriesDropDownFormat($allCategoriesStore, $categories);
     $condition = ['new' => trans('product.controller.new'), 'refurbished' => trans('product.controller.refurbished'), 'used' => trans('product.controller.used')];
     $edit = true;
     $panel = $this->panel;
     $oldFeatures = ProductDetail::oldFeatures($product->features);
     $productsDetails = new featuresHelper();
     return view('products.form', compact('product', 'panel', 'features', 'categories', 'condition', 'typeItem', 'disabled', 'edit', 'oldFeatures', 'productsDetails'));
 }
Example #4
0
 /**
  * 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, null, 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'));
 }