Commit d5c87d48fa8b0acd01c49329fa787dfdf902e017

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