lang->title; ?>
+sku; ?>
++ Цена:price ? : 0; ?> грн + + +
++ + + +
diff --git a/frontend/controllers/CategoryController.php b/frontend/controllers/CategoryController.php index 0358809..a2ce641 100755 --- a/frontend/controllers/CategoryController.php +++ b/frontend/controllers/CategoryController.php @@ -4,7 +4,6 @@ use artbox\catalog\helpers\FilterHelper; use artbox\catalog\models\Category; use artbox\core\components\SeoComponent; - use artbox\core\models\Page; use yii\data\ActiveDataProvider; use yii\db\ActiveQuery; use yii\web\Controller; @@ -38,7 +37,10 @@ $seo->setModel($model->lang); $filterHelper = \Yii::$app->get('filter'); $filterHelper->setFilter($filter); - $query = $filterHelper->buildQuery(); + $query = $filterHelper->buildQuery() + ->innerJoinWith('category', false) + ->andWhere([ 'product_to_category.category_id' => $model->id ]) + ->with('images', 'variants', 'lang'); $dataProvider = new ActiveDataProvider( [ 'query' => $query, @@ -62,7 +64,7 @@ * * @param $id * - * @return \artbox\core\models\Page + * @return Category * @throws \yii\web\NotFoundHttpException */ protected function findModel($id) @@ -72,7 +74,7 @@ */ $seo = Yii::$app->get('seo'); /** - * @var Page $model + * @var Category $model */ $model = Category::findWithFilters($id) ->with('lang.alias') diff --git a/frontend/controllers/ProductController.php b/frontend/controllers/ProductController.php new file mode 100755 index 0000000..304f625 --- /dev/null +++ b/frontend/controllers/ProductController.php @@ -0,0 +1,89 @@ +findModel($id); + /** + * @var SeoComponent $seo + */ + $seo = Yii::$app->get('seo'); + $seo->setModel($model->lang); + $variant = $model->variants[ 0 ]; + $groups = $variant->getSortedGroups(); + $similar = $model->getSimilarProducts(8); + + return $this->render( + 'view', + [ + 'model' => $model, + 'variant' => $variant, + 'groups' => $groups, + 'similar' => $similar, + ] + ); + } + + /** + * Find product by ID + * + * @param $id + * + * @return Product + * @throws \yii\web\NotFoundHttpException + */ + protected function findModel($id) + { + /** + * @var SeoComponent $seo + */ + $seo = \Yii::$app->get('seo'); + /** + * @var Product $model + */ + $model = Product::findWithFilters() + ->with('lang', 'images') + ->with( + [ + 'category' => function ($query) { + /** + * @var ActiveQuery $query + */ + $query->with('lang') + ->with('parent.lang'); + }, + ] + ) + ->where([ 'id' => $id ]) + ->one(); + if (!empty( $model )) { + if ($model->lang->alias_id !== $seo->aliasId) { + throw new NotFoundHttpException('Wrong language'); + } + return $model; + } else { + throw new NotFoundHttpException('Model not found'); + } + } + } \ No newline at end of file diff --git a/frontend/views/category/_product_item.php b/frontend/views/category/_product_item.php index 5eb314c..9e9f41a 100644 --- a/frontend/views/category/_product_item.php +++ b/frontend/views/category/_product_item.php @@ -1,28 +1,25 @@ get('imagemanager'); ?>
sku; ?>
++ Цена:price ? : 0; ?> грн + + +
+