Commit d5c87d48fa8b0acd01c49329fa787dfdf902e017
1 parent
29f1675f
site map
Showing
1 changed file
with
20 additions
and
10 deletions
Show diff stats
console/SiteMapController.php
| @@ -4,6 +4,7 @@ | @@ -4,6 +4,7 @@ | ||
| 4 | 4 | ||
| 5 | use artweb\artbox\ecommerce\models\Brand; | 5 | use artweb\artbox\ecommerce\models\Brand; |
| 6 | use artweb\artbox\ecommerce\models\ProductVariant; | 6 | use artweb\artbox\ecommerce\models\ProductVariant; |
| 7 | + use artweb\artbox\language\components\LanguageUrlManager; | ||
| 7 | use artweb\artbox\language\models\Language; | 8 | use artweb\artbox\language\models\Language; |
| 8 | use artweb\artbox\seo\models\Seo; | 9 | use artweb\artbox\seo\models\Seo; |
| 9 | use artweb\artbox\ecommerce\models\Category; | 10 | use artweb\artbox\ecommerce\models\Category; |
| @@ -134,16 +135,25 @@ | @@ -134,16 +135,25 @@ | ||
| 134 | 135 | ||
| 135 | $config = ArrayHelper::merge( | 136 | $config = ArrayHelper::merge( |
| 136 | require( \Yii::getAlias('@frontend/config/') . 'main.php' ), | 137 | require( \Yii::getAlias('@frontend/config/') . 'main.php' ), |
| 137 | - require( \Yii::getAlias('@common/config/') . 'main.php' ) | 138 | + require( \Yii::getAlias('@common/config/') . 'main.php' ), |
| 139 | + ['components'=>['urlManager'=>['hostInfo'=>'https://extremstyle.ua']]] | ||
| 138 | ); | 140 | ); |
| 139 | - | ||
| 140 | - Yii::$app->urlManager->addRules($config[ 'components' ][ 'urlManager' ][ 'rules' ]); | 141 | + |
| 142 | + if(isset($config['components']['urlManager']['class'])){ | ||
| 143 | + unset($config['components']['urlManager']['class']); | ||
| 144 | + } | ||
| 145 | + //Yii::$app->urlManager = new LanguageUrlManager($config['components']['urlManager']); | ||
| 146 | + | ||
| 147 | + $urlManager = new LanguageUrlManager($config['components']['urlManager']); | ||
| 148 | + | ||
| 141 | $this->mainMap = '<?xml version="1.0" encoding="UTF-8"?>'; | 149 | $this->mainMap = '<?xml version="1.0" encoding="UTF-8"?>'; |
| 142 | $this->mainMap .= '<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'; | 150 | $this->mainMap .= '<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'; |
| 143 | $this->fileName = 'sitemap' . $this->mapNumber . '.xml'; | 151 | $this->fileName = 'sitemap' . $this->mapNumber . '.xml'; |
| 144 | setlocale(LC_ALL, 'ru_RU.CP1251'); | 152 | setlocale(LC_ALL, 'ru_RU.CP1251'); |
| 145 | $this->handle = fopen(Yii::getAlias('@frontend') . '/web' . '/' . $this->fileName, "w"); | 153 | $this->handle = fopen(Yii::getAlias('@frontend') . '/web' . '/' . $this->fileName, "w"); |
| 146 | - | 154 | + |
| 155 | + | ||
| 156 | + | ||
| 147 | $this->content = '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'; | 157 | $this->content = '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'; |
| 148 | 158 | ||
| 149 | foreach ($this->getAddStatic() as $page) { | 159 | foreach ($this->getAddStatic() as $page) { |
| @@ -151,7 +161,7 @@ | @@ -151,7 +161,7 @@ | ||
| 151 | } | 161 | } |
| 152 | 162 | ||
| 153 | foreach ($this->getStaticPages() as $page) { | 163 | foreach ($this->getStaticPages() as $page) { |
| 154 | - $url = Url::to( | 164 | + $url = $urlManager->createAbsoluteUrl( |
| 155 | [ | 165 | [ |
| 156 | 'site/page', | 166 | 'site/page', |
| 157 | 'slug' => $page->lang->alias, | 167 | 'slug' => $page->lang->alias, |
| @@ -161,7 +171,7 @@ | @@ -161,7 +171,7 @@ | ||
| 161 | } | 171 | } |
| 162 | 172 | ||
| 163 | foreach ($this->getCategories() as $category) { | 173 | foreach ($this->getCategories() as $category) { |
| 164 | - $url = Url::to( | 174 | + $url = $urlManager->createAbsoluteUrl( |
| 165 | [ | 175 | [ |
| 166 | 'catalog/category', | 176 | 'catalog/category', |
| 167 | 'category' => $category->lang->alias, | 177 | 'category' => $category->lang->alias, |
| @@ -175,7 +185,7 @@ | @@ -175,7 +185,7 @@ | ||
| 175 | if(!preg_match("@^[a-zA-Z\d]+$@i", $row->sku)) { | 185 | if(!preg_match("@^[a-zA-Z\d]+$@i", $row->sku)) { |
| 176 | continue; | 186 | continue; |
| 177 | } | 187 | } |
| 178 | - $url = Url::to( | 188 | + $url = $urlManager->createAbsoluteUrl( |
| 179 | [ | 189 | [ |
| 180 | 'catalog/product', | 190 | 'catalog/product', |
| 181 | 'product' => $row->product->lang->alias, | 191 | 'product' => $row->product->lang->alias, |
| @@ -188,7 +198,7 @@ | @@ -188,7 +198,7 @@ | ||
| 188 | 198 | ||
| 189 | foreach ($this->getBrands() as $brand) { | 199 | foreach ($this->getBrands() as $brand) { |
| 190 | 200 | ||
| 191 | - $url = Url::to( | 201 | + $url = $urlManager->createAbsoluteUrl( |
| 192 | [ | 202 | [ |
| 193 | 'brand/view', | 203 | 'brand/view', |
| 194 | 'slug' => $brand->lang->alias, | 204 | 'slug' => $brand->lang->alias, |
| @@ -201,7 +211,7 @@ | @@ -201,7 +211,7 @@ | ||
| 201 | foreach ($this->getCategoriesWithFilters() as $category) { | 211 | foreach ($this->getCategoriesWithFilters() as $category) { |
| 202 | foreach ($category->taxGroups as $group) { | 212 | foreach ($category->taxGroups as $group) { |
| 203 | foreach ($group->taxOptions as $option) { | 213 | foreach ($group->taxOptions as $option) { |
| 204 | - $url = Url::to( | 214 | + $url = $urlManager->createAbsoluteUrl( |
| 205 | [ | 215 | [ |
| 206 | 'catalog/category', | 216 | 'catalog/category', |
| 207 | 'category' => $category, | 217 | 'category' => $category, |
| @@ -226,7 +236,7 @@ | @@ -226,7 +236,7 @@ | ||
| 226 | fclose($this->handle); | 236 | fclose($this->handle); |
| 227 | 237 | ||
| 228 | $this->mainMap .= '<sitemap>'. | 238 | $this->mainMap .= '<sitemap>'. |
| 229 | - '<loc>'.$this->getHost().'/ru/' . $this->fileName . '</loc>'. | 239 | + '<loc>'.$this->getHost(). $this->fileName . '</loc>'. |
| 230 | '<lastmod>' . date('Y-m-d') . '</lastmod>'. | 240 | '<lastmod>' . date('Y-m-d') . '</lastmod>'. |
| 231 | '</sitemap>'. | 241 | '</sitemap>'. |
| 232 | '</sitemapindex>'; | 242 | '</sitemapindex>'; |