From 6fa713cab9dd74a8008022c7b7703bb1099e8b30 Mon Sep 17 00:00:00 2001 From: Karnovsky A Date: Wed, 6 Apr 2016 12:01:55 +0300 Subject: [PATCH] Catalog v 1.2 --- .gitignore | 2 +- common/components/artboxtree/ArtboxTreeBehavior.php | 1 + common/config/main.php | 2 +- common/models/ProductVariant.php | 78 ------------------------------------------------------------------------------ common/modules/product/CatalogUrlManager.php | 154 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ common/modules/product/helpers/ProductHelper.php | 41 +++++++++++++++++++++++++++++++++++++++++ common/modules/product/models/BrandSearch.php | 36 ++++++++++++++++++++++++++++++++++++ common/modules/product/widgets/views/submenu.php | 6 +++--- common/modules/rubrication/models/TaxGroup.php | 2 ++ frontend/config/main.php | 19 ++++++++++++++----- frontend/controllers/CatalogController.old.php | 231 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ frontend/controllers/CatalogController.php | 199 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------------------------------------------------------------------------------------------------------------------- frontend/models/ProductFrontendSearch.php | 166 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ frontend/views/catalog/categories.php | 4 ++-- frontend/views/catalog/product.php | 4 ++-- frontend/views/catalog/product_item.php | 2 +- frontend/views/catalog/products.old.php | 278 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ frontend/views/catalog/products.php | 381 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- frontend/web/css/concat_all.css | 3 +++ frontend/web/js/my_scripts.js | 10 ---------- 20 files changed, 1165 insertions(+), 454 deletions(-) delete mode 100644 common/models/ProductVariant.php create mode 100644 common/modules/product/CatalogUrlManager.php create mode 100644 frontend/controllers/CatalogController.old.php create mode 100644 frontend/models/ProductFrontendSearch.php create mode 100644 frontend/views/catalog/products.old.php diff --git a/.gitignore b/.gitignore index 65f65aa..7560254 100644 --- a/.gitignore +++ b/.gitignore @@ -40,4 +40,4 @@ phpunit.phar /backend/web/assets/ /frontend/web/assets/ /frontend/web/css/node_modules/ -/frontend/views/вертска/ +composer.lock diff --git a/common/components/artboxtree/ArtboxTreeBehavior.php b/common/components/artboxtree/ArtboxTreeBehavior.php index 73a057f..3542deb 100644 --- a/common/components/artboxtree/ArtboxTreeBehavior.php +++ b/common/components/artboxtree/ArtboxTreeBehavior.php @@ -102,6 +102,7 @@ class ArtboxTreeBehavior extends Behavior { return $this->buildTree($query->all(), $this->owner->getAttribute($this->keyNameId)); } + // @todo Check algorytm public function buildTree(array $data, $parentId = 0) { $result = []; foreach ($data as $key => $element) { diff --git a/common/config/main.php b/common/config/main.php index 0ce7f94..3a6bf4e 100644 --- a/common/config/main.php +++ b/common/config/main.php @@ -116,7 +116,7 @@ return [ 'entity2' => [ 'model' => '\common\modules\rubrication\models\TaxOption', 'label' => 'Option', - 'listField' => 'ValueeRenderFlash', + 'listField' => 'ValueRenderFlash', 'key' => 'tax_option_id', 'linked_key' => 'option_id', ], diff --git a/common/models/ProductVariant.php b/common/models/ProductVariant.php deleted file mode 100644 index 8de21d3..0000000 --- a/common/models/ProductVariant.php +++ /dev/null @@ -1,78 +0,0 @@ - 255], - [['product_unit_id'], 'exist', 'skipOnError' => true, 'targetClass' => ProductUnit::className(), 'targetAttribute' => ['product_unit_id' => 'product_unit_id']], - ]; - } - - /** - * @inheritdoc - */ - public function attributeLabels() - { - return [ - 'product_variant_id' => Yii::t('app', 'Product Variant ID'), - 'product_id' => Yii::t('app', 'Product ID'), - 'name' => Yii::t('app', 'Name'), - 'sku' => Yii::t('app', 'Sku'), - 'price' => Yii::t('app', 'Price'), - 'price_old' => Yii::t('app', 'Price Old'), - 'stock' => Yii::t('app', 'Stock'), - 'product_unit_id' => Yii::t('app', 'Product Unit ID'), - ]; - } - - /** - * @return \yii\db\ActiveQuery - */ - public function getOrderItems() - { - return $this->hasMany(OrderItems::className(), ['item_id' => 'product_variant_id']); - } - - /** - * @return \yii\db\ActiveQuery - */ - public function getProductUnit() - { - return $this->hasOne(ProductUnit::className(), ['product_unit_id' => 'product_unit_id']); - } -} diff --git a/common/modules/product/CatalogUrlManager.php b/common/modules/product/CatalogUrlManager.php new file mode 100644 index 0000000..b051554 --- /dev/null +++ b/common/modules/product/CatalogUrlManager.php @@ -0,0 +1,154 @@ +getPathInfo(); + $paths = explode('/', $pathInfo); + + if (!array_key_exists($paths[0], $this->route_map)) { + return false; + } + + $params = []; + if ($paths[0] == 'catalog') { + $route = 'catalog/category'; + // Category + if (!empty($paths[1])) { + $category = CategorySearch::findByAlias($paths[1]); + if (empty($category)) { + http_redirect(Url::to(['/'])); + } + $params['category'] = $category; + } + // Filter + if (!empty($paths[2])) { + 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); + } + + } + } + } + } elseif ($paths[0] == 'product') { + $product = ProductSearch::findByAlias($paths[1]); + if (empty($product->product_id)) { + throw new HttpException(404 ,'Page not found'); + } + $route = 'catalog/product'; + $params = [ + 'product' => $product, + ]; + } elseif ($paths[0] == 'brand') { + + } + + return [$route, $params]; + } + /** + * Creates a URL according to the given route and parameters. + * @param \yii\web\UrlManager $manager the URL manager + * @param string $route the route. It should not have slashes at the beginning or the end. + * @param array $params the parameters + * @return string|boolean the created URL, or false if this rule cannot be used for creating this URL. + */ + public function createUrl($manager, $route, $params) + { + if (!in_array($route, $this->route_map)) { + return false; + } + + switch($route) { + case 'catalog/category': + if (!empty($params['category'])) { + $category_alias = is_object($params['category']) ? $params['category']->alias : strtolower($params['category']); + } + $url = 'catalog/'. $category_alias .'/'; + + $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); + } + return $url; + break; + + case 'catalog/product': + if (!empty($params['product'])) { + $product_alias = is_object($params['product']) ? $params['product']->alias : strtolower($params['product']); + } + $url = 'product/'. $product_alias; + return $url; + break; + } + } + + private function option_value_encode($value) { + return str_replace(array(',', '/'), array('~', '&s;'), $value); + } +} \ No newline at end of file diff --git a/common/modules/product/helpers/ProductHelper.php b/common/modules/product/helpers/ProductHelper.php index 3b51135..6662870 100644 --- a/common/modules/product/helpers/ProductHelper.php +++ b/common/modules/product/helpers/ProductHelper.php @@ -14,4 +14,45 @@ class ProductHelper extends Object { public static function getBrands() { return Brand::find()->with('brandName'); } + + /* + * Return custom filter-option link + * @var array $filter + * @var array $options + * @return array + */ + public static function getFilterForOption($filter, $key, $value, $remove = false) { + $result = $filter; + if (is_array($value)) { + foreach($value as $value_key => $value_items) { + if (!is_array($value_items)) { + $value_items = [$value_items]; + } + foreach($value_items as $value_item) { + if ($remove && isset($result[$key]) && ($i = array_search($value_item, $result[$key][$value_key])) !== FALSE) { + unset($result[$key][$value_key][$i]); + if (empty($result[$key][$value_key])) { + unset($result[$key][$value_key]); + } + } else { + if (!isset($result[$key][$value_key]) || array_search($value_item, $result[$key][$value_key]) === FALSE) { + $result[$key][$value_key][] = $value_item; + } + } + } + } + } else { + if ($remove && isset($result[$key]) && ($i = array_search($value, $result[$key])) !== FALSE) { + unset($result[$key][$i]); + if (empty($result[$key])) { + unset($result[$key]); + } + } else { + if (!isset($result[$key]) || array_search($value, $result[$key]) === FALSE) { + $result[$key][] = $value; + } + } + } + return $result; + } } \ No newline at end of file diff --git a/common/modules/product/models/BrandSearch.php b/common/modules/product/models/BrandSearch.php index 1bcb3b3..711aabf 100644 --- a/common/modules/product/models/BrandSearch.php +++ b/common/modules/product/models/BrandSearch.php @@ -72,4 +72,40 @@ class BrandSearch extends Brand return $dataProvider; } + + public function getBrands($category, $params) { + $query = Brand::find() + ->select([ + Brand::tableName() .'.*', + 'COUNT('. ProductCategory::tableName() .'.product_id) AS _items_count' + ]) + ->innerJoin(Product::tableName(), Product::tableName() .'.brand_id='. Brand::tableName() .'.brand_id') + ->innerJoin(ProductCategory::tableName(), ProductCategory::tableName() .'.product_id='. Product::tableName() .'.product_id') + + ->with('brandName') + ->where([ + ProductCategory::tableName() .'.category_id' => $category->category_id + ]) + ->groupBy(Brand::tableName() .'.brand_id'); + if (isset($params['options'])) { + unset($params['options']); + } + if (!empty($params['prices'])) { + if ($params['prices']['min'] > 0 || $params['prices']['max'] > 0) { + $query->innerJoin(ProductVariant::tableName(), ProductVariant::tableName() .'.product_id='. Product::tableName() .'.product_id'); + } + if ($params['prices']['min'] > 0) { + $query->andWhere(['>=', ProductVariant::tableName() .'.price', $params['prices']['min']]); + } + if ($params['prices']['max'] > 0) { + $query->andWhere(['<=', ProductVariant::tableName() .'.price', $params['prices']['max']]); + } + } + + $dataProvider = new ActiveDataProvider([ + 'query' => $query, + ]); + + return $dataProvider; + } } diff --git a/common/modules/product/widgets/views/submenu.php b/common/modules/product/widgets/views/submenu.php index b879e2a..dda048d 100644 --- a/common/modules/product/widgets/views/submenu.php +++ b/common/modules/product/widgets/views/submenu.php @@ -1,5 +1,5 @@ - -
-
categoryName->value?> ()
+
categoryName->value?> (totalCount?>)
- + count) :?>

По данному запросу товары не найдены.


-

Показать все товары из категории "categoryName->value?>"

+

Показать все товары из категории "categoryName->value?>"

- -
- -
- Сортировка: - $sort, - 'attributes' => [ - 'name', - 'price', - ] - ]); - ?> - -
+ +
+ +
+ Сортировка: + $productProvider->sort, + 'attributes' => [ + 'name', + 'price', + ] + ]); + ?> + +
-
- -
+
+ +
-
- totalCount > $pages->pageSize) :?> - Страница: - $pages, - 'options' => ['class' => 'pagination pull-right'], - ]); - ?> - + totalCount > $productProvider->pagination->pageSize) :?> +
+ Страница: + $productProvider->pagination, + 'options' => ['class' => 'pagination pull-right'], + ]); + ?> + +
-
- -
- -
-
-
-
- - - -
+
- totalCount > $pages->pageSize) :?> - - +
+
+
+
+ models as $product) :?> + + +
-
- Страница: - $pages, - 'options' => ['class' => 'pagination pull-right'], - ]); - ?> - -
- -
+ totalCount > $productProvider->pagination->pageSize) :?> + + + +
+ Страница: + $productProvider->pagination, + 'options' => ['class' => 'pagination pull-right'], + ]); + ?> + +
+ +
- description)) :?> -
- description?> + description)) :?> +
+ description?> -
+
+
+
-
-
-
- +
\ No newline at end of file diff --git a/frontend/web/css/concat_all.css b/frontend/web/css/concat_all.css index 2c88100..41a641f 100644 --- a/frontend/web/css/concat_all.css +++ b/frontend/web/css/concat_all.css @@ -104,6 +104,9 @@ .cat_p_filter_bar .filter_list .price_filter a { color: #6aa033; } +.cat_p_filter_bar .filter_list .price_filter.active-field { + display: block; +} .cat_p_filter_bar .filter_list .first_price_li { padding-top: 30px; diff --git a/frontend/web/js/my_scripts.js b/frontend/web/js/my_scripts.js index b3699d4..8bf74a0 100644 --- a/frontend/web/js/my_scripts.js +++ b/frontend/web/js/my_scripts.js @@ -2,16 +2,6 @@ $(document).ready(function(){ // ion tabs $.ionTabs("#tabs_1"); - // price rangeslider (filter price slider) - $("#example_id").ionRangeSlider({ - type: "double", - min: 0, - max: 500, - from: 50, - to: 450, - grid: false - }); - // ion checkradio init $("input[type='radio'], input[type='checkbox']").ionCheckRadio(); -- libgit2 0.21.4