Commit ddf2d8f9261262eeb9af271bb2e3fbe4a40c624a
1 parent
906f0fd5
big commti
Showing
2 changed files
with
17 additions
and
75 deletions
Show diff stats
common/modules/product/CatalogUrlManager.php
| ... | ... | @@ -2,12 +2,10 @@ |
| 2 | 2 | |
| 3 | 3 | namespace common\modules\product; |
| 4 | 4 | |
| 5 | -use common\modules\product\helpers\FilterHelper; | |
| 6 | -use common\modules\product\models\Brand; | |
| 7 | -use common\modules\product\models\BrandSearch; | |
| 5 | + | |
| 8 | 6 | use common\modules\product\models\CategorySearch; |
| 9 | 7 | use common\modules\product\models\ProductSearch; |
| 10 | -use common\modules\rubrication\models\TaxOption; | |
| 8 | + | |
| 11 | 9 | use Yii; |
| 12 | 10 | use yii\helpers\Url; |
| 13 | 11 | use yii\web\HttpException; |
| ... | ... | @@ -15,8 +13,6 @@ use yii\web\UrlRuleInterface; |
| 15 | 13 | |
| 16 | 14 | class CatalogUrlManager implements UrlRuleInterface { |
| 17 | 15 | public $route_map = []; |
| 18 | - | |
| 19 | - public $option_prefix = 'o:'; | |
| 20 | 16 | /** |
| 21 | 17 | * Parses the given request and returns the corresponding route and parameters. |
| 22 | 18 | * @param \yii\web\UrlManager $manager the URL manager |
| ... | ... | @@ -29,6 +25,12 @@ class CatalogUrlManager implements UrlRuleInterface { |
| 29 | 25 | $pathInfo = $request->getPathInfo(); |
| 30 | 26 | $paths = explode('/', $pathInfo); |
| 31 | 27 | |
| 28 | + if(isset($paths[1])) { | |
| 29 | + if(strripos($request->url,'catalog/'.$paths[1].'?') && (!strripos($request->url,'?page')) && (!strripos($request->url,'?sort'))){ | |
| 30 | + throw new HttpException(404 ,'Page not found'); | |
| 31 | + } | |
| 32 | + | |
| 33 | + } | |
| 32 | 34 | |
| 33 | 35 | |
| 34 | 36 | if (!array_key_exists($paths[0], $this->route_map)) { |
| ... | ... | @@ -54,24 +56,6 @@ class CatalogUrlManager implements UrlRuleInterface { |
| 54 | 56 | $this->parseFilter($paths[2], $params); |
| 55 | 57 | |
| 56 | 58 | } |
| 57 | - else if(strpos($paths[2], 'filter:') === 0){ | |
| 58 | - $this->parseOldFilter($paths[2], $params); | |
| 59 | - //['catalog/category', 'category' => $category, 'filters' =>$params['filter']] | |
| 60 | - | |
| 61 | - $optionsTemplate = FilterHelper::optionsTemplate(); | |
| 62 | - array_unshift($optionsTemplate, "special", "brands"); | |
| 63 | - $filterView = []; | |
| 64 | - foreach($optionsTemplate as $optionKey){ | |
| 65 | - if(isset($params['filter'][$optionKey])){ | |
| 66 | - $filterView[$optionKey] = $params['filter'][$optionKey]; | |
| 67 | - } | |
| 68 | - | |
| 69 | - | |
| 70 | - } | |
| 71 | - | |
| 72 | - | |
| 73 | - Yii::$app->response->redirect(['catalog/category', 'category' => $category, 'filters' =>$filterView],301); | |
| 74 | - } | |
| 75 | 59 | else { |
| 76 | 60 | throw new HttpException(404 ,'Page not found'); |
| 77 | 61 | } |
| ... | ... | @@ -111,6 +95,7 @@ class CatalogUrlManager implements UrlRuleInterface { |
| 111 | 95 | if (!empty($params['category'])) { |
| 112 | 96 | $category_alias = is_object($params['category']) ? $params['category']->alias : strtolower($params['category']); |
| 113 | 97 | $url = 'catalog/'. $category_alias .'/'; |
| 98 | + unset($params['category']); | |
| 114 | 99 | } else { |
| 115 | 100 | $url = 'catalog/'; |
| 116 | 101 | } |
| ... | ... | @@ -133,6 +118,7 @@ class CatalogUrlManager implements UrlRuleInterface { |
| 133 | 118 | case 'catalog/product': |
| 134 | 119 | if (!empty($params['product'])) { |
| 135 | 120 | $product_alias = is_object($params['product']) ? $params['product']->alias : strtolower($params['product']); |
| 121 | + unset($params['product']); | |
| 136 | 122 | } |
| 137 | 123 | $url = 'product/'. $product_alias; |
| 138 | 124 | |
| ... | ... | @@ -145,23 +131,6 @@ class CatalogUrlManager implements UrlRuleInterface { |
| 145 | 131 | return $url; |
| 146 | 132 | break; |
| 147 | 133 | |
| 148 | -// case 'catalog/brands': | |
| 149 | -// if (empty($params['brand'])) { | |
| 150 | -// return 'brands'; | |
| 151 | -// } else { | |
| 152 | -// | |
| 153 | -// $brand_alias = is_object($params['brand']) ? $params['brand']->alias : strtolower($params['brand']); | |
| 154 | -// } | |
| 155 | -// $url = 'brands/'. $brand_alias .'/'; | |
| 156 | -// | |
| 157 | -// $this->setFilterUrl($params, $url); | |
| 158 | -// | |
| 159 | -// if (!empty($params) && ($query = http_build_query($params)) !== '') { | |
| 160 | -// $url .= '?' . $query; | |
| 161 | -// } | |
| 162 | -// | |
| 163 | -// return $url; | |
| 164 | -// break; | |
| 165 | 134 | } |
| 166 | 135 | } |
| 167 | 136 | |
| ... | ... | @@ -201,12 +170,8 @@ class CatalogUrlManager implements UrlRuleInterface { |
| 201 | 170 | $filter_str = substr($paths, 8); |
| 202 | 171 | $filter_options = explode(';', $filter_str); |
| 203 | 172 | foreach ($filter_options as $filter_option) { |
| 204 | - if (empty($filter_option)) { | |
| 205 | - continue; | |
| 206 | - } | |
| 207 | 173 | $filter_exp = explode('=', $filter_option); |
| 208 | - | |
| 209 | - if(isset($filter_exp[1])){ | |
| 174 | + if(is_array($filter_exp)){ | |
| 210 | 175 | list($filter_key, $filter_option) = explode('=', $filter_option); |
| 211 | 176 | if($filter_key == 'prices') { // price-interval section |
| 212 | 177 | $prices = explode(':', $filter_option); |
| ... | ... | @@ -221,34 +186,7 @@ class CatalogUrlManager implements UrlRuleInterface { |
| 221 | 186 | } else { |
| 222 | 187 | throw new HttpException(404 ,'Page not found'); |
| 223 | 188 | } |
| 224 | - | |
| 225 | 189 | } |
| 226 | 190 | } |
| 227 | 191 | |
| 228 | - | |
| 229 | - | |
| 230 | - private function parseOldFilter($paths, &$params) { | |
| 231 | - $params['filter'] = []; | |
| 232 | - $filter_str = substr($paths, 7); | |
| 233 | - $filter_options = explode(';', $filter_str); | |
| 234 | - foreach ($filter_options as $filter_option) { | |
| 235 | - if (empty($filter_option)) { | |
| 236 | - continue; | |
| 237 | - } | |
| 238 | - list($filter_key, $filter_option) = explode('=', $filter_option); | |
| 239 | - if($filter_key == 'prices') { // price-interval section | |
| 240 | - $prices = explode(':', $filter_option); | |
| 241 | - $params['filter'][$filter_key] = [ | |
| 242 | - 'min' => floatval($prices[0]), | |
| 243 | - 'max' => floatval($prices[1]), | |
| 244 | - ]; | |
| 245 | - } | |
| 246 | - elseif (strpos($filter_key, $this->option_prefix) === 0) { // options section | |
| 247 | - $params['filter'][substr($filter_key, 2)] = explode(',', $filter_option); | |
| 248 | - } | |
| 249 | - else { // brands and other sections | |
| 250 | - $params['filter'][$filter_key] = explode(',', $filter_option); | |
| 251 | - } | |
| 252 | - } | |
| 253 | - } | |
| 254 | 192 | } |
| 255 | 193 | \ No newline at end of file | ... | ... |
frontend/widgets/Seo.php
| ... | ... | @@ -153,7 +153,7 @@ class Seo extends Widget |
| 153 | 153 | $title = $this->selectSeoData(self::TITLE); |
| 154 | 154 | |
| 155 | 155 | |
| 156 | - if(!empty($filter) && isset($this->fields['meta-title']) && $title == $this->fields['meta-title']) { | |
| 156 | + if(!empty($filter) && isset($this->fields['meta-title']) && $title == $this->fields['meta-title'] || !empty($filter) && empty($title)) { | |
| 157 | 157 | $array = $this->arrayBuilder($filter); |
| 158 | 158 | |
| 159 | 159 | $title_string = $this->getTitleString($array); |
| ... | ... | @@ -184,9 +184,13 @@ class Seo extends Widget |
| 184 | 184 | } else { |
| 185 | 185 | |
| 186 | 186 | $filter = \Yii::$app->request->get('filters', []); |
| 187 | + | |
| 187 | 188 | if(!empty($filter)){ |
| 188 | 189 | $array = $this->arrayBuilder($filter); |
| 189 | - return $this->getDescriptionString($array); | |
| 190 | + $this->getView()->registerMetaTag([ | |
| 191 | + 'name' => 'description', | |
| 192 | + 'content' => $this->getDescriptionString($array) | |
| 193 | + ]); | |
| 190 | 194 | } |
| 191 | 195 | |
| 192 | 196 | } | ... | ... |