/**
  * Displays a single Product model.
  * @param string $alias
  * @return mixed
  */
 public function actionView($alias)
 {
     $model = $this->findModel($alias);
     $menu_items_product = Product::getItemsProductMenu($model->category_id);
     $menu_items_category = Category::getItemsCategoryMenu($model->category->parent_category_id, $model->category_id);
     return $this->render('view', ['model' => $model, 'menu_items_product' => $menu_items_product, 'menu_items_category' => $menu_items_category]);
 }
 /**
  * Displays a single Category model.
  * @param string $alias
  * @return mixed
  */
 public function actionView($alias)
 {
     $model = $this->findModel($alias);
     $menu_items_product = Product::getItemsProductMenu($model->id);
     $menu_items_category = Category::getItemsCategoryMenu($model->parent_category_id);
     $sort = new Sort(['attributes' => ['price' => ['asc' => ['price' => SORT_ASC], 'desc' => ['price' => SORT_DESC], 'default' => SORT_DESC]]]);
     $query = Product::find()->where(['active' => 1, 'category_id' => $model->id]);
     $countQuery = clone $query;
     $pages = new Pagination(['totalCount' => $countQuery->count(), 'defaultPageSize' => Yii::$app->params['PageSize']]);
     $items_product = $query->offset($pages->offset)->limit($pages->limit)->orderBy($sort->orders)->all();
     // тут вытягиваем все главные картинки одним запросом
     $arItems = [];
     foreach ($items_product as $value) {
         $arItems[] = $value->id;
     }
     $images = $model->getImagesMain($arItems, 'Product');
     return $this->render('view', ['model' => $model, 'menu_items_product' => $menu_items_product, 'menu_items_category' => $menu_items_category, 'items_product' => $items_product, 'pages' => $pages, 'sort' => $sort, 'images' => $images]);
 }