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'); ?>
images )) { - $image = $product->images[ 0 ]->id; + $image = $product->images[ 0 ]; } else { $image = null; } echo Html::a( Html::img( - $image ? $imageManager->getImagePath($image) : '/img/no-image.png', + $image ? $image->getUrl() : '/img/no-image.png', [ 'class' => 'img-responsive-image1', ] diff --git a/frontend/views/product/view.php b/frontend/views/product/view.php new file mode 100755 index 0000000..2da04f4 --- /dev/null +++ b/frontend/views/product/view.php @@ -0,0 +1,268 @@ +get('seo'); + if (!empty( $model->category )) { + if (!empty( $model->category->parent )) { + $this->params[ 'breadcrumbs' ][] = [ + 'label' => $model->category->parent->lang->title, + 'url' => [ + '/category/view', + 'id' => $model->category->parent->id, + ], + ]; + } + $this->params[ 'breadcrumbs' ][] = [ + 'label' => $model->category->lang->title, + 'url' => [ + '/category/view', + 'id' => $model->category->id, + ], + ]; + } + $this->params[ 'breadcrumbs' ][] = $seo->title; +?> +
+
+
+
+ +
+
+
+ images )) { + echo ImageHelper::set($model->images[ 0 ]->getPath()) + ->fillResize(555, 555) + ->renderImage( + [ + 'class' => 'img-responsive', + 'alt' => $model->lang->title, + 'title' => $model->lang->title, + ] + ); + } else { + echo ImageHelper::set('@frontend/web/img/no-image.png') + ->fillResize(555, 555) + ->renderImage( + [ + 'class' => 'img-responsive', + 'alt' => $model->lang->title, + 'title' => $model->lang->title, + ] + ); + } + ?> +
+ + is(2)) { + ?> +
+
SALE
+
+
+ + is(1)) { + ?> +
+
NEW
+
+
+ + + +
+ images )) { + foreach ($model->images as $image) { + echo Html::tag( + 'div', + Html::a( + ImageHelper::set($image->getPath()) + ->fillResize(70, 60) + ->renderImage( + [ + 'class' => 'img-responsive', + 'alt' => $model->lang->title, + 'title' => $model->lang->title, + ] + ), + ImageHelper::set($image->getPath()) + ->fillResize(555, 555) + ->render(), + [ + 'class' => 'thumb', + ] + ), + [ + 'class' => 'col-xs-2', + ] + ); + } + } else { + echo Html::tag( + 'div', + Html::a( + ImageHelper::set('@frontend/web/img/no-image.png') + ->fillResize(70, 60) + ->renderImage( + [ + 'class' => 'img-responsive', + 'alt' => $model->lang->title, + 'title' => $model->lang->title, + ] + ), + ImageHelper::set('@frontend/web/img/no-image.png') + ->fillResize(555, 555) + ->render(), + [ + 'class' => 'thumb', + ] + ), + [ + 'class' => 'col-xs-2', + ] + ); + } + ?> +
+ video )) { + ?> +
+
+ +
+
+ video; ?> +
+
+ +
+
+
+

lang->title; ?>

+

sku; ?>

+

+ Цена:price ? : 0; ?> грн  + + +

+
+ + +   +
+
+

+ lang->description ? : \Yii::t('app', 'Нет описания'); ?> +
+ +
+

+ + + lang->title, + [ 'class' => 'td-title' ] + ) . Html::tag( + 'td', + implode( + ', ', + ArrayHelper::getColumn( + $optionGroup->currentOptions, + 'lang.value' + ) + ) + ) + ); + } + } + ?> + +
+
+
+ +
+ + +
+

+
+ + + +
+ +
+ +
+ +
+ diff --git a/frontend/web/css/style.css b/frontend/web/css/style.css index e7af010..01312be 100644 --- a/frontend/web/css/style.css +++ b/frontend/web/css/style.css @@ -2806,10 +2806,6 @@ p.no-margin { .products { content: " "; display: table; - -} - -.row.products { width: 100%; } -- libgit2 0.21.4