diff --git a/common/modules/product/CatalogUrlManager.php b/common/modules/product/CatalogUrlManager.php index a618211..909fde5 100755 --- a/common/modules/product/CatalogUrlManager.php +++ b/common/modules/product/CatalogUrlManager.php @@ -2,12 +2,10 @@ namespace common\modules\product; -use common\modules\product\helpers\FilterHelper; -use common\modules\product\models\Brand; -use common\modules\product\models\BrandSearch; + use common\modules\product\models\CategorySearch; use common\modules\product\models\ProductSearch; -use common\modules\rubrication\models\TaxOption; + use Yii; use yii\helpers\Url; use yii\web\HttpException; @@ -15,8 +13,6 @@ use yii\web\UrlRuleInterface; class CatalogUrlManager implements UrlRuleInterface { public $route_map = []; - - public $option_prefix = 'o:'; /** * Parses the given request and returns the corresponding route and parameters. * @param \yii\web\UrlManager $manager the URL manager @@ -29,6 +25,12 @@ class CatalogUrlManager implements UrlRuleInterface { $pathInfo = $request->getPathInfo(); $paths = explode('/', $pathInfo); + if(isset($paths[1])) { + if(strripos($request->url,'catalog/'.$paths[1].'?') && (!strripos($request->url,'?page')) && (!strripos($request->url,'?sort'))){ + throw new HttpException(404 ,'Page not found'); + } + + } if (!array_key_exists($paths[0], $this->route_map)) { @@ -54,24 +56,6 @@ class CatalogUrlManager implements UrlRuleInterface { $this->parseFilter($paths[2], $params); } - else if(strpos($paths[2], 'filter:') === 0){ - $this->parseOldFilter($paths[2], $params); - //['catalog/category', 'category' => $category, 'filters' =>$params['filter']] - - $optionsTemplate = FilterHelper::optionsTemplate(); - array_unshift($optionsTemplate, "special", "brands"); - $filterView = []; - foreach($optionsTemplate as $optionKey){ - if(isset($params['filter'][$optionKey])){ - $filterView[$optionKey] = $params['filter'][$optionKey]; - } - - - } - - - Yii::$app->response->redirect(['catalog/category', 'category' => $category, 'filters' =>$filterView],301); - } else { throw new HttpException(404 ,'Page not found'); } @@ -111,6 +95,7 @@ class CatalogUrlManager implements UrlRuleInterface { if (!empty($params['category'])) { $category_alias = is_object($params['category']) ? $params['category']->alias : strtolower($params['category']); $url = 'catalog/'. $category_alias .'/'; + unset($params['category']); } else { $url = 'catalog/'; } @@ -133,6 +118,7 @@ class CatalogUrlManager implements UrlRuleInterface { case 'catalog/product': if (!empty($params['product'])) { $product_alias = is_object($params['product']) ? $params['product']->alias : strtolower($params['product']); + unset($params['product']); } $url = 'product/'. $product_alias; @@ -145,23 +131,6 @@ class CatalogUrlManager implements UrlRuleInterface { return $url; break; -// case 'catalog/brands': -// if (empty($params['brand'])) { -// return 'brands'; -// } else { -// -// $brand_alias = is_object($params['brand']) ? $params['brand']->alias : strtolower($params['brand']); -// } -// $url = 'brands/'. $brand_alias .'/'; -// -// $this->setFilterUrl($params, $url); -// -// if (!empty($params) && ($query = http_build_query($params)) !== '') { -// $url .= '?' . $query; -// } -// -// return $url; -// break; } } @@ -201,12 +170,8 @@ class CatalogUrlManager implements UrlRuleInterface { $filter_str = substr($paths, 8); $filter_options = explode(';', $filter_str); foreach ($filter_options as $filter_option) { - if (empty($filter_option)) { - continue; - } $filter_exp = explode('=', $filter_option); - - if(isset($filter_exp[1])){ + if(is_array($filter_exp)){ list($filter_key, $filter_option) = explode('=', $filter_option); if($filter_key == 'prices') { // price-interval section $prices = explode(':', $filter_option); @@ -221,34 +186,7 @@ class CatalogUrlManager implements UrlRuleInterface { } else { throw new HttpException(404 ,'Page not found'); } - } } - - - private function parseOldFilter($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'][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/frontend/widgets/Seo.php b/frontend/widgets/Seo.php index cfadfa6..21667b2 100755 --- a/frontend/widgets/Seo.php +++ b/frontend/widgets/Seo.php @@ -153,7 +153,7 @@ class Seo extends Widget $title = $this->selectSeoData(self::TITLE); - if(!empty($filter) && isset($this->fields['meta-title']) && $title == $this->fields['meta-title']) { + if(!empty($filter) && isset($this->fields['meta-title']) && $title == $this->fields['meta-title'] || !empty($filter) && empty($title)) { $array = $this->arrayBuilder($filter); $title_string = $this->getTitleString($array); @@ -184,9 +184,13 @@ class Seo extends Widget } else { $filter = \Yii::$app->request->get('filters', []); + if(!empty($filter)){ $array = $this->arrayBuilder($filter); - return $this->getDescriptionString($array); + $this->getView()->registerMetaTag([ + 'name' => 'description', + 'content' => $this->getDescriptionString($array) + ]); } } -- libgit2 0.21.4