diff --git a/common/modules/product/CatalogUrlManager.php b/common/modules/product/CatalogUrlManager.php index 6e194a6..acaa7a7 100755 --- a/common/modules/product/CatalogUrlManager.php +++ b/common/modules/product/CatalogUrlManager.php @@ -45,27 +45,7 @@ class CatalogUrlManager implements UrlRuleInterface { if (!empty($paths[2])) { // Filter if (strpos($paths[2], 'filter:') === 0) { - $params['filter'] = []; - $filter_str = substr($paths[2], 7); - $filter_options = explode(';', $filter_str); - foreach ($filter_options as $filter_option) { - if (empty($filter_option)) { - continue; - } - list($filter_key, $filter_option) = explode('=', $filter_option); - if($filter_key == 'prices') { // price-interval section - $prices = explode(':', $filter_option); - $params['filter'][$filter_key] = [ - 'min' => floatval($prices[0]), - 'max' => floatval($prices[1]), - ]; - } elseif (strpos($filter_key, $this->option_prefix) === 0) { // options section - $params['filter']['options'][substr($filter_key, 2)] = explode(',', $filter_option); - } else { // brands and other sections - $params['filter'][$filter_key] = explode(',', $filter_option); - } - - } + $this->parseFilter($paths[2], $params); } elseif (strpos($paths[2], 'word:') === 0) { $params['word'] = substr($paths[2], 5); } @@ -83,8 +63,14 @@ class CatalogUrlManager implements UrlRuleInterface { if (empty($paths[1]) || $paths[1] == 'index') { $route = 'catalog/brands'; } elseif (($brand = BrandSearch::findByAlias($paths[1]))) { - $route = 'catalog/brands'; + $route = 'catalog/brand'; $params['brand'] = $brand; + if (!empty($paths[2])) { + // Filter + if (strpos($paths[2], 'filter:') === 0) { + $this->parseFilter($paths[2], $params); + } + } } else { // @todo redirect or return FALSE } @@ -123,40 +109,7 @@ class CatalogUrlManager implements UrlRuleInterface { unset($params['word']); } - $filter = []; - if (!empty($params['filter'])) { - foreach ($params['filter'] as $key => $values) { - switch($key) { - case 'prices': - $filter[] = $key .'='. implode(':', $values); - break; - - case 'options': - foreach($values as $group => &$value_items) { - foreach($value_items as &$value_item) { - $value_item = $this->option_value_encode($value_item); - if (empty($value_item)) { - unset($value_item); - } - } - $filter[] = $this->option_prefix. $group .'='. implode(',', $value_items); - } - break; - - default: - foreach($values as &$value) { - $value = $this->option_value_encode($value); - if (empty($value)) { - unset($value); - } - } - $filter[] = $key .'='. implode(',', $values); - break; - } - } - $url .= 'filter:'. implode(';', $filter); - unset($params['filter']); - } + $this->setFilterUrl($params, $url); if (!empty($params) && ($query = http_build_query($params)) !== '') { $url .= '?' . $query; @@ -184,7 +137,9 @@ class CatalogUrlManager implements UrlRuleInterface { } else { $brand_alias = is_object($params['brand']) ? $params['brand']->alias : strtolower($params['brand']); } - $url = 'brands/'. $brand_alias; + $url = 'brands/'. $brand_alias .'/'; + + $this->setFilterUrl($params, $url); if (!empty($params) && ($query = http_build_query($params)) !== '') { $url .= '?' . $query; @@ -198,4 +153,64 @@ class CatalogUrlManager implements UrlRuleInterface { private function option_value_encode($value) { return str_replace(array(',', '/'), array('~', '&s;'), $value); } + + private function setFilterUrl(&$params, &$url) { + $filter = []; + if (!empty($params['filter'])) { + foreach ($params['filter'] as $key => $values) { + switch($key) { + case 'prices': + $filter[] = $key .'='. implode(':', $values); + break; + + case 'options': + foreach($values as $group => &$value_items) { + foreach($value_items as &$value_item) { + $value_item = $this->option_value_encode($value_item); + if (empty($value_item)) { + unset($value_item); + } + } + $filter[] = $this->option_prefix. $group .'='. implode(',', $value_items); + } + break; + + default: + foreach($values as &$value) { + $value = $this->option_value_encode($value); + if (empty($value)) { + unset($value); + } + } + $filter[] = $key .'='. implode(',', $values); + break; + } + } + $url .= 'filter:'. implode(';', $filter); + unset($params['filter']); + } + } + + private function parseFilter($paths, &$params) { + $params['filter'] = []; + $filter_str = substr($paths, 7); + $filter_options = explode(';', $filter_str); + foreach ($filter_options as $filter_option) { + if (empty($filter_option)) { + continue; + } + list($filter_key, $filter_option) = explode('=', $filter_option); + if($filter_key == 'prices') { // price-interval section + $prices = explode(':', $filter_option); + $params['filter'][$filter_key] = [ + 'min' => floatval($prices[0]), + 'max' => floatval($prices[1]), + ]; + } elseif (strpos($filter_key, $this->option_prefix) === 0) { // options section + $params['filter']['options'][substr($filter_key, 2)] = explode(',', $filter_option); + } else { // brands and other sections + $params['filter'][$filter_key] = explode(',', $filter_option); + } + } + } } \ No newline at end of file diff --git a/common/modules/product/models/Product.php b/common/modules/product/models/Product.php index 591bd04..0f21f7f 100755 --- a/common/modules/product/models/Product.php +++ b/common/modules/product/models/Product.php @@ -7,6 +7,7 @@ use common\modules\rubrication\models\TaxOption; use Yii; use common\modules\relation\relationBehavior; use yii\db\ActiveQuery; +use yii\db\ActiveRecord; use yii\helpers\Html; use yii\web\UploadedFile; @@ -237,6 +238,12 @@ class Product extends \yii\db\ActiveRecord } } + public function beforeDelete() { + ProductImage::deleteAll(['product_id' => $this->product_id]); + ProductCategory::deleteAll(['product_id' => $this->product_id]); + ProductVariant::deleteAll(['product_id' => $this->product_id]); + } + public function imagesUpload() { if ($this->validate()) { diff --git a/frontend/controllers/CatalogController.php b/frontend/controllers/CatalogController.php index b2c7e56..f764fba 100755 --- a/frontend/controllers/CatalogController.php +++ b/frontend/controllers/CatalogController.php @@ -203,9 +203,30 @@ class CatalogController extends \yii\web\Controller ]); } - public function actionBrand($alias) + public function actionBrand($brand) { - return 'actionBrand:'. $alias; + $filter = Yii::$app->request->get('filter', []); + + $params = [ + 'brand_id' => $brand->brand_id, + ]; + + if ( !empty($filter['prices']) ) { + $params['prices'] = $filter['prices']; + } + + $productModel = new ProductFrontendSearch(); + $productProvider = $productModel->search(null, $params); + + $priceLimits = $productModel->priceLimits(null, $params); + + return $this->render('brand', [ + 'productModel' => $productModel, + 'productProvider' => $productProvider, + 'brand' => $brand, + 'priceLimits' => $priceLimits, + 'filter' => $filter, + ]); } } diff --git a/frontend/views/catalog/brand.php b/frontend/views/catalog/brand.php new file mode 100644 index 0000000..aa4f578 --- /dev/null +++ b/frontend/views/catalog/brand.php @@ -0,0 +1,154 @@ +title = $brand->name; +$this->params['breadcrumbs'][] = ['label' => Yii::t('products', 'Brands'), 'url' => ['catalog/brands']]; +$this->params['breadcrumbs'][] = $brand->name; + +$this->params['seo']['seo_text'] = 'TEST SEO TEXT'; +$this->params['seo']['h1'] = 'TEST H1'; +$this->params['seo']['description'] = 'TEST DESCRIPTION'; +$this->params['seo']['fields']['name'] = 'TEST NAME FROM FIELD'; +$this->params['seo']['key']= 'product_list'; + +$this->registerCssFile (Yii::getAlias('@web/css/ion.rangeSlider.css')); +$this->registerCssFile (Yii::getAlias('@web/css/ion.rangeSlider.skinHTML5.css')); +$this->registerJsFile (Yii::getAlias('@web/js/ion.rangeSlider.js')); +?> + + + + + +
+
+
+
    +
  • + $brand, 'filter' => ProductHelper::getFilterForOption($filter, 'special', 'new', $checked)]); + ?> + onchange="document.location=''" /> + +
  • +
  • + $brand, 'filter' => ProductHelper::getFilterForOption($filter, 'special', 'top', $checked)]); + ?> + onchange="document.location=''" /> + +
  • +
  • + $brand, 'filter' => ProductHelper::getFilterForOption($filter, 'special', 'promo', $checked)]); + ?> + onchange="document.location=''" /> + +
  • +
+
+
+ + + + + +
+
Цена
+
+
+ +
+
+
+ +
+
+ +
+

name ?>

+
+ +
+ Сортировка: + $productProvider->sort, + 'attributes' => [ + 'name', + 'price', + ] + ]); + ?> +
+
+
+
    + models as $product) :?> + + +
+
+
+ totalCount > $productProvider->pagination->pageSize) :?> + $productProvider->pagination, + 'options' => ['class' => 'pagination pull-right'], + 'registerLinkTags' => true, + ]); + ?> + +
+
+
+ + +
\ No newline at end of file diff --git a/frontend/widgets/Rubrics.php b/frontend/widgets/Rubrics.php index d5a868c..159af8e 100755 --- a/frontend/widgets/Rubrics.php +++ b/frontend/widgets/Rubrics.php @@ -32,7 +32,7 @@ class Rubrics extends Widget { $items = []; if (empty($this->categories)) { - $this->categories = Category::find ()->all(); + $this->categories = Category::find ()->orderBy('category_id', SORT_ASC)->all(); } foreach ($this->categories as $category) { if (!empty($this->includes) && !in_array($category->category_id, $this->includes)) { -- libgit2 0.21.4