group() public method

public group ( $group )
 /**
  * Display the specified resource.
  *
  * @param int $id
  *
  * @return Response
  */
 public function show($id)
 {
     $user = \Auth::user();
     $allWishes = '';
     $panel = ['center' => ['width' => '12']];
     if ($user) {
         $allWishes = Order::ofType('wishlist')->where('user_id', $user->id)->where('description', '<>', '')->orderBy('id', 'desc')->take(5)->get();
     }
     $product = Product::select(['id', 'category_id', 'user_id', 'name', 'description', 'price', 'stock', 'features', 'condition', 'rate_val', 'rate_count', 'low_stock', 'status', 'type', 'tags', 'products_group', 'brand'])->with(['group' => function ($query) {
         $query->select(['id', 'products_group', 'features']);
     }])->with('categories')->find($id);
     if ($product) {
         //if there is a user in session, the admin menu will be shown
         if ($user && $user->id == $product->user_id) {
             $panel = ['left' => ['width' => '2'], 'center' => ['width' => '10']];
         }
         //retrieving products features
         $features = ProductDetail::all()->toArray();
         //increasing product counters, in order to have a suggestion orden
         $this->setCounters($product, ['view_counts' => trans('globals.product_value_counters.view')], 'viewed');
         //saving the product tags into users preferences
         if (trim($product->tags) != '') {
             UserController::setPreferences('product_viewed', explode(',', $product->tags));
         }
         //receiving products user reviews & comments
         $reviews = OrderDetail::where('product_id', $product->id)->whereNotNull('rate_comment')->select('rate', 'rate_comment', 'updated_at')->orderBy('updated_at', 'desc')->take(5)->get();
         //If it is a free product, we got to retrieve its package information
         if ($product->type == 'freeproduct') {
             $order = OrderDetail::where('product_id', $product->id)->first();
             $freeproduct = FreeProductOrder::where('order_id', $order->order_id)->first();
         }
         $freeproductId = isset($freeproduct) ? $freeproduct->freeproduct_id : 0;
         //products suggestions control
         //saving product id into suggest-listed, in order to exclude products from suggestions type "view"
         Session::push('suggest-listed', $product->id);
         $suggestions = $this->getSuggestions(['preferences_key' => $product->id, 'limit' => 4]);
         Session::forget('suggest-listed');
         //retrieving products groups of the product shown
         if (count($product->group)) {
             $featuresHelper = new featuresHelper();
             $product->group = $featuresHelper->group($product->group);
         }
         return view('products.detailProd', compact('product', 'panel', 'allWishes', 'reviews', 'freeproductId', 'features', 'suggestions'));
     } else {
         return redirect(route('products'));
     }
 }
示例#2
0
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function show($id)
 {
     $user = \Auth::user();
     $allWishes = '';
     $panel = array('center' => ['width' => '12']);
     if ($user) {
         $allWishes = Order::ofType('wishlist')->where('user_id', $user->id)->where('description', '<>', '')->orderBy('id', 'desc')->take(5)->get();
     }
     $product = Product::select('id', 'category_id', 'user_id', 'name', 'description', 'price', 'stock', 'features', 'condition', 'rate_val', 'rate_count', 'low_stock', 'status', 'type', 'tags', 'products_group', 'brand')->with(['group' => function ($query) {
         $query->select('id', 'products_group', 'features');
     }])->find($id);
     if ($product) {
         if ($user && $user->id == $product->user_id) {
             $panel = array('left' => ['width' => '2'], 'center' => ['width' => '10']);
         }
         $features = ProductDetail::all()->toArray();
         //Increasing product counters.
         $this->setCounters($product, ['view_counts' => trans('globals.product_value_counters.view')], 'viewed');
         //saving tags in users preferences
         if (trim($product->tags) != '') {
             UserController::setPreferences('product_viewed', explode(',', $product->tags));
         }
         $details = OrderDetail::where('product_id', $product->id)->whereNotNull('rate_comment')->select('rate', 'rate_comment', 'updated_at')->orderBy('updated_at', 'desc')->take(5)->get();
         $jsonDetails = json_encode($details->toArray());
         //Si es un producto de tipo free, debemos buscar a que paquete freeproduct pertenece
         if ($product->type == 'freeproduct') {
             $order = OrderDetail::where('product_id', $product->id)->first();
             $freeproduct = FreeProductOrder::where('order_id', $order->order_id)->first();
         }
         $freeproductId = isset($freeproduct) ? $freeproduct->freeproduct_id : 0;
         Session::push('suggest-listed', $product->id);
         $suggestions = $this->getSuggestions(['preferences_key' => $product->id, 'limit' => 4]);
         Session::forget('suggest-listed');
         if (count($product->group)) {
             $featuresHelper = new featuresHelper();
             $product->group = $featuresHelper->group($product->group);
         }
         return view('products.show', compact('product', 'panel', 'allWishes', 'jsonDetails', 'freeproductId', 'features', 'suggestions'));
     } else {
         return redirect(route('products'));
     }
 }