diff --git a/frontend/config/main.php b/frontend/config/main.php index ce4d0a4..67f489e 100755 --- a/frontend/config/main.php +++ b/frontend/config/main.php @@ -64,7 +64,9 @@ 'route' => 'category/view', 'defaults' => [ 'filter' => '' ], ], - 'robots.txt' => 'site/robots', + 'special/' => 'special/index', + 'special//' => 'special/category', + 'robots.txt' => 'site/robots', ], ], ], diff --git a/frontend/controllers/SpecialController.php b/frontend/controllers/SpecialController.php new file mode 100755 index 0000000..6846a84 --- /dev/null +++ b/frontend/controllers/SpecialController.php @@ -0,0 +1,116 @@ +with('lang.alias') + ->innerJoinWith('products', false) + ->groupBy('category.id'); + if ($type === 'new') { + $query->where('product.mask & 2 != 0'); + $productQuery = Product::find() + ->where('product.mask & 2 != 0'); + } else { + $query->where('product.mask & 4 != 0'); + $productQuery = Product::find() + ->where('product.mask & 4 != 0'); + } + $categories = $query->all(); + $dataProvider = new ActiveDataProvider( + [ + 'query' => $productQuery, + ] + ); + return $this->render( + 'index', + [ + 'categories' => $categories, + 'dataProvider' => $dataProvider, + ] + ); + } + + /** + * Show specials by type and category + * + * @param $type + * @param $category + * + * @return string + */ + public function actionCategory($type, $category) + { + $model = $this->findCategory($category); + $query = Product::find() + ->with('variants', 'image') + ->innerJoinWith('categories', 'false') + ->where([ 'product_to_category.category_id' => $model->id ]) + ->orderBy( + [ + 'product.sort' => SORT_ASC, + 'product.created_at' => SORT_DESC, + ] + ); + if ($type === 'new') { + $query->andWhere('product.mask & 2 != 0'); + } elseif ($type === 'sale') { + $query->andWhere('product.mask & 4 != 0'); + } + $dataProvider = new ActiveDataProvider( + [ + 'query' => $query, + ] + ); + return $this->render( + 'category', + [ + 'model' => $model, + 'dataProvider' => $dataProvider, + ] + ); + } + + /** + * @param string $category + * + * @return Category + * @throws \yii\web\NotFoundHttpException + */ + protected function findCategory(string $category) + { + /** + * @var Category $model + */ + $model = Category::find() + ->innerJoinWith('lang.alias', false) + ->where([ 'alias.value' => $category ]) + ->one(); + if (!empty($model)) { + 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 f9ebb7d..c8dfbee 100644 --- a/frontend/views/category/_product_item.php +++ b/frontend/views/category/_product_item.php @@ -5,89 +5,89 @@ use yii\web\View; /** - * @var View $this - * @var Product $product + * @var View $this + * @var Product $product */ ?>
-
-
- image ? $product->image->getPath() : '@frontend/web/img/no-image.png' - ) - ->fillResize(260, 260) - ->render(), - [ - 'class' => 'img-responsive-image1', - ] - ), +
+
+ image ? $product->image->getPath() : '@frontend/web/img/no-image.png' + ) + ->fillResize(260, 260) + ->render(), [ - 'product/view', - 'id' => $product->id, + 'class' => 'img-responsive-image1', ] - ); - ?> -
- -
-

- lang->title, - [ - 'product/view', - 'id' => $product->id, - ] - ); - ?> -

-

- variants[ 0 ]->price_old) { - echo Html::tag('del', $product->variants[ 0 ]->price_old); - } - echo $product->variants[ 0 ]->price; - ?>

-

- 'fa fa-shopping-cart', - ] - ) . \Yii::t('app', 'В корзину'), - '#', - [ 'class' => 'btn btn-template-main' ] - ); - ?> -

-
- - is(1)) { - ?> -
-
-
-
- is(2)) { - ?> -
-
-
-
- $product->id, + ] + ); ?> - -
- + +
+

+ lang->title, + [ + 'product/view', + 'id' => $product->id, + ] + ); + ?> +

+

+ variants[ 0 ]->price_old) { + echo Html::tag('del', $product->variants[ 0 ]->price_old . ' грн.'); + } + echo ( $product->variants[ 0 ]->price ? : 0 ) . ' грн.'; + ?>

+

+ 'fa fa-shopping-cart', + ] + ) . \Yii::t('app', 'В корзину'), + '#', + [ 'class' => 'btn btn-template-main' ] + ); + ?> +

+
+ + is('new')) { + ?> +
+
+
+
+ is('akcia')) { + ?> +
+
+
+
+ + + +
+
diff --git a/frontend/views/category/view.php b/frontend/views/category/view.php index 5fab149..1ca6de0 100755 --- a/frontend/views/category/view.php +++ b/frontend/views/category/view.php @@ -96,6 +96,32 @@ _________________________________________________________ --> + + getFilter())) { + echo Html::a( + Html::icon( + 'times-circle', + [ + 'prefix' => 'fa fa-', + ] + ) . Html::tag( + 'span', + \Yii::t('app', 'Сбросить фильтр'), + [ + 'class' => 'hidden-sm', + ] + ), + [ + 'view', + 'category' => $model->lang->alias->value, + ], + [ + 'class' => 'btn btn-xs btn-danger', + ] + ); + } + ?> getBrands($model); diff --git a/frontend/views/layouts/main.php b/frontend/views/layouts/main.php index cdd686b..402cb98 100755 --- a/frontend/views/layouts/main.php +++ b/frontend/views/layouts/main.php @@ -77,526 +77,526 @@ ?> beginPage() ?> - - - - - - - - <?= Html::encode($seo->title) ?> - head() ?> - - - beginBody() ?> - - +
+
+ + + + + + + + + + - +
+ 'sub-title', + ] + ), + [ + '/basket/index', + ], + [ + 'class' => 'cart-item-link', + ] + ); + ?> +
-
-
-
-

- -

about; ?>

- -
- -

Join our monthly newsletter

- '/site/subscribe', - ] - ); - echo Html::beginTag( - 'div', - [ - 'class' => 'input-group', - ] - ); - echo $newsletterForm->field( - $newsletter, - 'email', - [ - 'options' => [ - 'tag' => false, - ], - ] - ) - ->label(false) - ->textInput(); - echo Html::tag( - 'span', - Html::button( - Html::tag( - 'i', - '', + - - -
+ ), + [ + 'class' => 'btn btn-template-main', + ] + ), + [ + 'class' => 'input-group-btn', + ] + ); + echo Html::endTag('div'); + $searchForm::end(); + ?> +
+ + + +
+
+ +
+ + -

+ -
-
-
- - - -
- -
- -
-
- - - -
- -
+ - - -
+ +
+
-

- -

- name ? Html::tag('strong', $settings->name) : ''; - echo $settings->office ? Html::tag('br') . $settings->office : ''; - echo $settings->street ? Html::tag( - 'br' - ) . $settings->street . ' ' . $settings->house : ''; - echo $settings->city ? Html::tag('br') . $settings->city : ''; - echo $settings->country ? Html::tag('br') . Html::tag( - 'strong', - $settings->country - ) : ''; - ?> -

+ - Go to contact page - - - -
- - - -
+ + +
+
+ isset($this->params[ 'breadcrumbs' ]) ? $this->params[ 'breadcrumbs' ] : [], + 'homeLink' => [ + 'label' => \Yii::t('app', 'Home'), + 'url' => [ '/site/index' ], + ], + ] + ) ?> +
+
+ + + + -

+ -
-
- - # - -
-
- - # - -
-
- - # - -
-
- - # - -
-
- - # - -
-
- - # - -
-
- -
- - - - - +
+
+
+

+ +

about; ?>

+ +
+ +

Join our monthly newsletter

+ '/site/subscribe', + ] + ); + echo Html::beginTag( + 'div', + [ + 'class' => 'input-group', + ] + ); + echo $newsletterForm->field( + $newsletter, + 'email', + [ + 'options' => [ + 'tag' => false, + ], + ] + ) + ->label(false) + ->textInput(); + echo Html::tag( + 'span', + Html::button( + Html::tag( + 'i', + '', + [ + 'class' => 'fa fa-send', + ] + ), + [ + 'class' => 'btn btn-default', + ] + ), + [ + 'class' => 'input-group-btn', + ] + ); + echo Html::endTag('div'); + $newsletterForm::end(); + ?> + + +
+ + +
+ +

+ +
+
+
+ + + +
+ +
+ +
+
+ + + +
+ +
- + +
+ + + +
+ + +
+ +

+ +

+ name ? Html::tag('strong', $settings->name) : ''; + echo $settings->office ? Html::tag('br') . $settings->office : ''; + echo $settings->street ? Html::tag( + 'br' + ) . $settings->street . ' ' . $settings->house : ''; + echo $settings->city ? Html::tag('br') . $settings->city : ''; + echo $settings->country ? Html::tag('br') . Html::tag( + 'strong', + $settings->country + ) : ''; + ?> +

+ + Go to contact page + + +
- - endBody() ?> - - + + + +
+ +

+ +
+
+ + # + +
+
+ + # + +
+
+ + # + +
+
+ + # + +
+
+ + # + +
+
+ + # + +
+
+ +
+ +
+ +
+ + + + + + endBody() ?> + + endPage() ?> \ No newline at end of file diff --git a/frontend/views/product/view.php b/frontend/views/product/view.php index 90bd8fd..139106c 100755 --- a/frontend/views/product/view.php +++ b/frontend/views/product/view.php @@ -75,7 +75,7 @@ is(2)) { + if ($model->is('akcia')) { ?>
SALE
@@ -84,7 +84,7 @@ is(1)) { + if ($model->is('new')) { ?>
NEW
diff --git a/frontend/views/site/_slider_product.php b/frontend/views/site/_slider_product.php index d6c6283..3a193b0 100644 --- a/frontend/views/site/_slider_product.php +++ b/frontend/views/site/_slider_product.php @@ -47,9 +47,9 @@

variants[ 0 ]->price_old) { - echo Html::tag('del', $product->variants[ 0 ]->price_old); + echo Html::tag('del', $product->variants[ 0 ]->price_old . ' грн.'); } - echo $product->variants[ 0 ]->price; + echo $product->variants[ 0 ]->price ? : 0 . ' грн.'; ?>

is(1)) { + if ($product->is('new')) { ?>

@@ -77,7 +77,7 @@
is(2)) { + if ($product->is('akcia')) { ?>
diff --git a/frontend/views/special/category.php b/frontend/views/special/category.php new file mode 100644 index 0000000..2464811 --- /dev/null +++ b/frontend/views/special/category.php @@ -0,0 +1,87 @@ +get('seo'); + $view = $this; + $type = \Yii::$app->request->get('type'); + $this->params[ 'breadcrumbs' ][] = [ + 'label' => \Yii::t( + 'app', + 'Все {type}', + [ + 'type' => ( $type === 'new' ) ? \Yii::t('app', 'новинки') : \Yii::t( + 'app', + 'акционные' + ), + ] + ), + 'url' => [ + 'special/index', + 'type' => $type, + ], + ]; + $this->params[ 'breadcrumbs' ][] = $seo->title ? : ( ( $type === 'new' ) ? \Yii::t('app', 'Новинки') : \Yii::t( + 'app', + 'Акционные' + ) ) . ' ' . $model->lang->title; +?> +
+
+ +
+ +
+ + [ + 'class' => 'row products', + ], + 'itemOptions' => [ + 'tag' => false, + ], + 'layout' => '{items}', + 'dataProvider' => $dataProvider, + 'itemView' => function ($model) use ($view) { + /** + * @var Product $model + */ + return $view->render( + '@frontend/views/category/_product_item', + [ + 'product' => $model, + ] + ); + }, + ] + ); + echo Html::tag( + 'div', + LinkPager::widget( + [ + 'pagination' => $dataProvider->pagination, + ] + ), + [ + 'class' => 'pages', + ] + ); + ?> + +
+ +
+ +
+ +
+ diff --git a/frontend/views/special/index.php b/frontend/views/special/index.php new file mode 100644 index 0000000..687117d --- /dev/null +++ b/frontend/views/special/index.php @@ -0,0 +1,114 @@ +request->get('type'); + $seo = \Yii::$app->get('seo'); + $view = $this; + $this->params[ 'breadcrumbs' ][] = $seo->title ? : \Yii::t( + 'app', + 'Все {type}', + [ + 'type' => ( $type === 'new' ) ? \Yii::t('app', 'новинки') : \Yii::t( + 'app', + 'акционные' + ), + ] + ); +?> +
+
+ +
+ + + + +
+ +
+ + + + + + +
+ + [ + 'class' => 'row products', + ], + 'itemOptions' => [ + 'tag' => false, + ], + 'layout' => '{items}', + 'dataProvider' => $dataProvider, + 'itemView' => function ($model) use ($view) { + /** + * @var Product $model + */ + return $view->render( + '@frontend/views/category/_product_item', + [ + 'product' => $model, + ] + ); + }, + ] + ); + echo Html::tag( + 'div', + LinkPager::widget( + [ + 'pagination' => $dataProvider->pagination, + ] + ), + [ + 'class' => 'pages', + ] + ); + ?> + +
+ + + + +
+ +
+ +
+ + diff --git a/frontend/widgets/LangLink.php b/frontend/widgets/LangLink.php index 3115aca..920de81 100644 --- a/frontend/widgets/LangLink.php +++ b/frontend/widgets/LangLink.php @@ -68,6 +68,39 @@ } else { $this->links[ $languageId ] = $url; } + } elseif (\Yii::$app->requestedRoute == 'special/category') { + $aliasValue = \Yii::$app->request->get('category'); + if (!empty($aliasValue)) { + $aliases = Alias::find() + ->where( + [ + 'route' => Alias::find() + ->select('route') + ->where([ 'value' => $aliasValue ]), + ] + ) + ->andWhere( + [ + 'language_id' => [ + $languageId, + Language::getCurrent()->id, + ], + ] + ) + ->asArray() + ->all(); + $map = $this->mapAliases($aliases); + $params = $this->replaceParams($map); + $this->links[ $languageId ] = Html::a( + $url, + Url::to( + [ \Yii::$app->requestedRoute ] + $params + [ 'language_id' => $languageId ], + true + ) + ); + } else { + $this->links[ $languageId ] = $url; + } } else { $this->links[ $languageId ] = Html::a( $url, @@ -115,7 +148,9 @@ protected function replaceParams(array $map): array { $params = \Yii::$app->request->get(); - $filter = explode('_', $params[ 'filter' ]); + if (isset($params[ 'filter' ])) { + $filter = explode('_', $params[ 'filter' ]); + } if (array_key_exists($params[ 'category' ], $map)) { $params[ 'category' ] = $map[ $params[ 'category' ] ]; } -- libgit2 0.21.4