Commit 9580e5482327795294b95a11ab704470ec950a5a
1 parent
f36d238b
-Site map in progress. Need to split
Showing
1 changed file
with
108 additions
and
64 deletions
Show diff stats
console/SiteMapController.php
... | ... | @@ -2,6 +2,9 @@ |
2 | 2 | |
3 | 3 | namespace artweb\artbox\ecommerce\console; |
4 | 4 | |
5 | + use artweb\artbox\ecommerce\models\Brand; | |
6 | + use artweb\artbox\ecommerce\models\ProductVariant; | |
7 | + use artweb\artbox\language\models\Language; | |
5 | 8 | use artweb\artbox\seo\models\Seo; |
6 | 9 | use artweb\artbox\ecommerce\models\Category; |
7 | 10 | use artweb\artbox\ecommerce\models\Product; |
... | ... | @@ -18,7 +21,7 @@ |
18 | 21 | class SiteMapController extends Controller |
19 | 22 | { |
20 | 23 | |
21 | - private $urlList = [ 'http://www.rukzachok.com.ua/' ]; | |
24 | + private $urlList = [ 'https://dev.extremstyle.ua/ru' ]; | |
22 | 25 | private $count = 1; |
23 | 26 | |
24 | 27 | public function checkFilter($category, $filter) |
... | ... | @@ -35,15 +38,16 @@ |
35 | 38 | public function getAddStatic() |
36 | 39 | { |
37 | 40 | return [ |
38 | - 'http://www.rukzachok.com.ua', | |
39 | - 'http://www.rukzachok.com.ua/catalog', | |
41 | + 'https://dev.extremstyle.ua/ru', | |
40 | 42 | ]; |
41 | 43 | } |
42 | 44 | |
43 | - public function getProducts() | |
45 | + public function getVariants() | |
44 | 46 | { |
45 | - return Product::find() | |
46 | - ->all(); | |
47 | + return ProductVariant::find() | |
48 | + ->with('lang') | |
49 | + ->with('product.lang') | |
50 | + ->batch(1000); | |
47 | 51 | |
48 | 52 | } |
49 | 53 | |
... | ... | @@ -58,19 +62,32 @@ |
58 | 62 | public function getStaticPages() |
59 | 63 | { |
60 | 64 | return Page::find() |
65 | + ->with('lang') | |
61 | 66 | ->all(); |
62 | 67 | } |
63 | 68 | |
64 | 69 | public function getCategories() |
65 | 70 | { |
66 | 71 | return Category::find() |
72 | + ->with('lang') | |
67 | 73 | ->all(); |
68 | 74 | } |
69 | 75 | |
70 | - public function getBrands($category) | |
76 | + public function getCategoriesWithFilters() | |
71 | 77 | { |
72 | - | |
73 | - return $category->brands; | |
78 | + return Category::find() | |
79 | + ->with('lang') | |
80 | + ->joinWith('taxGroups.lang') | |
81 | + ->with('taxGroups.taxOptions.lang') | |
82 | + ->where(['tax_group.meta_robots' => '',]) | |
83 | + ->all(); | |
84 | + } | |
85 | + | |
86 | + public function getBrands() | |
87 | + { | |
88 | + return Brand::find() | |
89 | + ->joinWith('lang') | |
90 | + ->all(); | |
74 | 91 | } |
75 | 92 | |
76 | 93 | /** |
... | ... | @@ -81,8 +98,13 @@ |
81 | 98 | |
82 | 99 | public function getFilters($category) |
83 | 100 | { |
84 | - | |
85 | 101 | return $category->getActiveFilters() |
102 | + ->andWhere( | |
103 | + [ | |
104 | + | |
105 | + 'tax_group.meta_robots' => '', | |
106 | + ] | |
107 | + ) | |
86 | 108 | ->all(); |
87 | 109 | |
88 | 110 | } |
... | ... | @@ -100,16 +122,15 @@ |
100 | 122 | public function createRow($url, $priority, &$content) |
101 | 123 | { |
102 | 124 | if ($this->checkUrl($url)) { |
103 | - print $this->count++ . "\n"; | |
125 | + print $this->count++ . $url . "\n"; | |
104 | 126 | $content .= '<url>' . '<loc>' . $url . '</loc>' . '<lastmod>' . date( |
105 | 127 | 'Y-m-d' |
106 | - ) . '</lastmod>' . '<changefreq>Daily</changefreq>' . '<priority>' . $priority . '</priority>' . '</url>'; | |
128 | + ) . '</lastmod>' . '<changefreq>Weekly</changefreq>' . '<priority>' . $priority . '</priority>' . '</url>'; | |
107 | 129 | } |
108 | 130 | } |
109 | 131 | |
110 | 132 | public function actionProcess() |
111 | 133 | { |
112 | - | |
113 | 134 | $config = ArrayHelper::merge( |
114 | 135 | require( \Yii::getAlias('@frontend/config/') . 'main.php' ), |
115 | 136 | require( \Yii::getAlias('@common/config/') . 'main.php' ) |
... | ... | @@ -119,8 +140,7 @@ |
119 | 140 | |
120 | 141 | $dirName = Yii::getAlias('@frontend') . '/web'; |
121 | 142 | |
122 | - $filename = 'sitemap.xml'; | |
123 | - | |
143 | + $filename = 'test_sitemap.xml'; | |
124 | 144 | setlocale(LC_ALL, 'ru_RU.CP1251'); |
125 | 145 | $handle = fopen($dirName . '/' . $filename, "w"); |
126 | 146 | |
... | ... | @@ -133,8 +153,8 @@ |
133 | 153 | foreach ($this->getStaticPages() as $page) { |
134 | 154 | $url = Url::to( |
135 | 155 | [ |
136 | - 'text/index', | |
137 | - 'translit' => $page->translit, | |
156 | + 'site/page', | |
157 | + 'slug' => $page->lang->alias, | |
138 | 158 | ] |
139 | 159 | ); |
140 | 160 | $this->createRow($url, 1, $content); |
... | ... | @@ -144,53 +164,45 @@ |
144 | 164 | $url = Url::to( |
145 | 165 | [ |
146 | 166 | 'catalog/category', |
147 | - 'category' => $category, | |
167 | + 'category' => $category->lang->alias, | |
148 | 168 | ] |
149 | 169 | ); |
150 | - $this->createRow($url, 1, $content); | |
170 | + $this->createRow($url, 0.8, $content); | |
171 | + } | |
172 | + | |
173 | + foreach ($this->getVariants() as $rows) { | |
174 | + foreach ($rows as $row) { | |
175 | + $url = Url::to( | |
176 | + [ | |
177 | + 'catalog/product', | |
178 | + 'product' => $row->product->lang->alias, | |
179 | + 'variant' => $row->sku, | |
180 | + ] | |
181 | + ); | |
182 | + $this->createRow($url, 0.9, $content); | |
183 | + } | |
151 | 184 | } |
152 | 185 | |
153 | - foreach ($this->getProducts() as $product) { | |
154 | - | |
186 | + foreach ($this->getBrands() as $brand) { | |
187 | + | |
155 | 188 | $url = Url::to( |
156 | 189 | [ |
157 | - 'catalog/product', | |
158 | - 'product' => $product, | |
190 | + 'brand/view', | |
191 | + 'slug' => $brand->lang->alias, | |
159 | 192 | ] |
160 | 193 | ); |
161 | - $this->createRow($url, 0.9, $content); | |
162 | - } | |
163 | - | |
164 | - // foreach ($this->getArticles() as $article) { | |
165 | - // | |
166 | - // $url = Url::to(['articles/show', 'translit' => $article->translit, 'id' => $article->id,]); | |
167 | - // $this->createRow($url , 0.8,$content); | |
168 | - // | |
169 | - // } | |
170 | - | |
171 | - foreach ($this->getCategories() as $category) { | |
172 | - foreach ($this->getBrands($category) as $brand) { | |
173 | - if ($this->checkFilter($category, [ 'brands' => [ $brand->id ] ])) { | |
174 | - $url = Url::to( | |
175 | - [ | |
176 | - 'catalog/category', | |
177 | - 'category' => $category, | |
178 | - 'filters' => [ 'brands' => [ $brand->alias ] ], | |
179 | - ] | |
180 | - ); | |
181 | - $this->createRow($url, 0.8, $content); | |
182 | - } | |
183 | - } | |
194 | + $this->createRow($url, 0.7, $content); | |
195 | + | |
184 | 196 | } |
185 | 197 | |
186 | - foreach ($this->getCategories() as $category) { | |
187 | - foreach ($this->getFilters($category) as $filter) { | |
188 | - if ($this->checkFilter($category, [ $filter[ 'group_alias' ] => [ $filter[ 'option_alias' ] ] ])) { | |
198 | + foreach ($this->getCategoriesWithFilters() as $category) { | |
199 | + foreach ($category->taxGroups as $group) { | |
200 | + foreach ($group->taxOptions as $option) { | |
189 | 201 | $url = Url::to( |
190 | 202 | [ |
191 | 203 | 'catalog/category', |
192 | 204 | 'category' => $category, |
193 | - 'filters' => [ $filter[ 'group_alias' ] => [ $filter[ 'option_alias' ] ] ], | |
205 | + 'filters' => [ $group->lang->alias => [ $option->lang->alias ] ], | |
194 | 206 | ] |
195 | 207 | ); |
196 | 208 | $this->createRow($url, 0.8, $content); |
... | ... | @@ -202,28 +214,60 @@ |
202 | 214 | foreach ($this->getSeoLinks() as $link) { |
203 | 215 | $url = Yii::$app->urlManager->baseUrl . $link->url; |
204 | 216 | $this->createRow($url, 0.7, $content); |
205 | - | |
217 | + | |
206 | 218 | } |
207 | 219 | |
208 | - // foreach($this->getCategories() as $category){ | |
209 | - // foreach ($this->getFilters($category) as $filter1) { | |
210 | - // foreach ($this->getFilters($category) as $filter2) { | |
211 | - // if($this->checkFilter($category, [$filter1['group_alias'] => [$filter1['option_alias']],$filter2['group_alias'] => [$filter2['option_alias']]] )){ | |
212 | - // $url = Url::to(['catalog/category', 'category' => $category, 'filters' => [$filter1['group_alias'] => [$filter1['option_alias']],$filter2['group_alias'] => [$filter2['option_alias']]] ]); | |
213 | - // $this->createRow($url , 0.7, $content); | |
220 | + // foreach ($this->getCategories() as $category) { | |
221 | + // foreach ($this->getFilters($category) as $filter1) { | |
222 | + // foreach ($this->getFilters($category) as $filter2) { | |
223 | + // if ($this->checkFilter( | |
224 | + // $category, | |
225 | + // [ | |
226 | + // $filter1[ 'group_alias' ] => [ $filter1[ 'option_alias' ] ], | |
227 | + // $filter2[ 'group_alias' ] => [ $filter2[ 'option_alias' ] ], | |
228 | + // ] | |
229 | + // ) | |
230 | + // ) { | |
231 | + // $url = Url::to( | |
232 | + // [ | |
233 | + // 'catalog/category', | |
234 | + // 'category' => $category, | |
235 | + // 'filters' => [ | |
236 | + // $filter1[ 'group_alias' ] => [ $filter1[ 'option_alias' ] ], | |
237 | + // $filter2[ 'group_alias' ] => [ $filter2[ 'option_alias' ] ], | |
238 | + // ], | |
239 | + // ] | |
240 | + // ); | |
241 | + // $this->createRow($url, 0.7, $content); | |
242 | + // } | |
243 | + // | |
214 | 244 | // } |
215 | 245 | // |
216 | - // } | |
246 | + // foreach ($this->getBrands($category) as $brand) { | |
247 | + // if ($this->checkFilter( | |
248 | + // $category, | |
249 | + // [ | |
250 | + // 'brands' => [ $brand->id ], | |
251 | + // $filter1[ 'group_alias' ] => [ $filter1[ 'option_alias' ] ], | |
252 | + // ] | |
253 | + // ) | |
254 | + // ) { | |
255 | + // $url = Url::to( | |
256 | + // [ | |
257 | + // 'catalog/category', | |
258 | + // 'category' => $category, | |
259 | + // 'filters' => [ | |
260 | + // 'brands' => [ $brand->alias ], | |
261 | + // $filter1[ 'group_alias' ] => [ $filter1[ 'option_alias' ] ], | |
262 | + // ], | |
263 | + // ] | |
264 | + // ); | |
265 | + // $this->createRow($url, 0.7, $content); | |
266 | + // } | |
217 | 267 | // |
218 | - // foreach ($this->getBrands($category) as $brand) { | |
219 | - // if($this->checkFilter($category, ['brands' => [$brand->id], $filter1['group_alias'] => [$filter1['option_alias']]] )){ | |
220 | - // $url = Url::to(['catalog/category', 'category' => $category, 'filters' => ['brands' => [$brand->alias],$filter1['group_alias'] => [$filter1['option_alias']]]]); | |
221 | - // $this->createRow($url , 0.7,$content); | |
222 | 268 | // } |
223 | - // | |
224 | 269 | // } |
225 | 270 | // } |
226 | - // } | |
227 | 271 | |
228 | 272 | $content .= '</urlset>'; |
229 | 273 | ... | ... |