public function actionIndex($lang = null, $path = null) { $categoryIds = []; /** @var $category CategoryRecord*/ $category = null; if (empty($path)) { $categoryList = CategoryRecord::find()->select('id')->lang($lang)->all(); foreach ($categoryList as $categoryItem) { $categoryIds[] = $categoryItem->id; } } else { $categoryModel = new CategoryRecord(); $category = $categoryModel->findByFullPath($path); if (!$category) { throw new HttpException(404, 'Категория не найдена'); } $categoryList = $category->childrens(); $categoryIds[] = $category->id; foreach ($categoryList as $categoryItem) { $categoryIds[] = $categoryItem->id; } } $productList = ProductRecord::find()->lang($lang)->andWhere(['categoryId' => $categoryIds])->all(); $template = $category->templateList ? $category->templateList : 'default'; return $this->render('index/' . $template, ['category' => $category, 'productList' => $productList]); }
public static function getFirstLink($alias) { if (!empty(self::$firstLink[$alias])) { return self::$firstLink[$alias]; } $modelRecord = new CategoryRecord(); $model = $modelRecord->findByFullPath($alias); if (!$model) { return null; } self::$firstLink[$alias] = $model->url; return self::getFirstLink($alias); }
public function getProducts($path, $limit = 12, $lang = 'ru') { $categoryModel = new CategoryRecord(); $category = $categoryModel->findByFullPath($path, $limit); if (!$category) { return []; } $categoryList = $category->childrens(); $categoryIds[] = $category->id; foreach ($categoryList as $categoryItem) { $categoryIds[] = $categoryItem->id; } $productList = ProductRecord::find()->lang($lang)->andWhere(['categoryId' => $categoryIds])->all(); return $productList ? $productList : []; }