Commit 3d1a900d2413f04f0230e04ce1950f619a6a7c05
1 parent
315ebf90
sitemap controller fix noindex
Showing
1 changed file
with
34 additions
and
13 deletions
Show diff stats
console/controllers/SiteMapController.php
@@ -30,21 +30,28 @@ class SiteMapController extends Controller | @@ -30,21 +30,28 @@ class SiteMapController extends Controller | ||
30 | private $count = 1; | 30 | private $count = 1; |
31 | 31 | ||
32 | public function getAddStatic() { | 32 | public function getAddStatic() { |
33 | + | ||
33 | return [ | 34 | return [ |
34 | 'http://www.rukzachok.com.ua', | 35 | 'http://www.rukzachok.com.ua', |
35 | 'http://www.rukzachok.com.ua/catalog' | 36 | 'http://www.rukzachok.com.ua/catalog' |
36 | ]; | 37 | ]; |
38 | + | ||
37 | } | 39 | } |
38 | 40 | ||
39 | public function getStaticPages() { | 41 | public function getStaticPages() { |
42 | + | ||
40 | return Page::find()->all(); | 43 | return Page::find()->all(); |
44 | + | ||
41 | } | 45 | } |
42 | 46 | ||
43 | public function getCategories() { | 47 | public function getCategories() { |
48 | + | ||
44 | return Category::find()->andWhere(['meta_robots' => ''])->all(); | 49 | return Category::find()->andWhere(['meta_robots' => ''])->all(); |
50 | + | ||
45 | } | 51 | } |
46 | 52 | ||
47 | public function checkFilter($category, $filter) { | 53 | public function checkFilter($category, $filter) { |
54 | + | ||
48 | $productModel = new ProductFrontendSearch(); | 55 | $productModel = new ProductFrontendSearch(); |
49 | $productProvider = $productModel->search($category, $filter); | 56 | $productProvider = $productModel->search($category, $filter); |
50 | if(!empty($productProvider->models)){ | 57 | if(!empty($productProvider->models)){ |
@@ -52,19 +59,25 @@ class SiteMapController extends Controller | @@ -52,19 +59,25 @@ class SiteMapController extends Controller | ||
52 | } else { | 59 | } else { |
53 | return false; | 60 | return false; |
54 | } | 61 | } |
62 | + | ||
55 | } | 63 | } |
56 | 64 | ||
57 | public function getProducts() { | 65 | public function getProducts() { |
66 | + | ||
58 | return Product::find()->all(); | 67 | return Product::find()->all(); |
59 | 68 | ||
60 | } | 69 | } |
61 | 70 | ||
62 | public function getSeoLinks() { | 71 | public function getSeoLinks() { |
72 | + | ||
63 | return Seo::find()->where(['meta' => ''])->all(); | 73 | return Seo::find()->where(['meta' => ''])->all(); |
74 | + | ||
64 | } | 75 | } |
65 | 76 | ||
66 | public function getArticles() { | 77 | public function getArticles() { |
78 | + | ||
67 | return Articles::find()->all(); | 79 | return Articles::find()->all(); |
80 | + | ||
68 | } | 81 | } |
69 | 82 | ||
70 | public function getBrands($category) { | 83 | public function getBrands($category) { |
@@ -94,9 +107,11 @@ class SiteMapController extends Controller | @@ -94,9 +107,11 @@ class SiteMapController extends Controller | ||
94 | $this->urlList[] = $url; | 107 | $this->urlList[] = $url; |
95 | return true; | 108 | return true; |
96 | } | 109 | } |
110 | + | ||
97 | } | 111 | } |
98 | 112 | ||
99 | public function createRow( $url, $priority, &$content ) { | 113 | public function createRow( $url, $priority, &$content ) { |
114 | + | ||
100 | if($this->checkUrl($url)){ | 115 | if($this->checkUrl($url)){ |
101 | print $this->count++ . "\n"; | 116 | print $this->count++ . "\n"; |
102 | $content .= '<url>' . | 117 | $content .= '<url>' . |
@@ -106,6 +121,7 @@ class SiteMapController extends Controller | @@ -106,6 +121,7 @@ class SiteMapController extends Controller | ||
106 | '<priority>' . $priority .'</priority>' . | 121 | '<priority>' . $priority .'</priority>' . |
107 | '</url>'; | 122 | '</url>'; |
108 | } | 123 | } |
124 | + | ||
109 | } | 125 | } |
110 | 126 | ||
111 | public function actionProcess() { | 127 | public function actionProcess() { |
@@ -123,6 +139,7 @@ class SiteMapController extends Controller | @@ -123,6 +139,7 @@ class SiteMapController extends Controller | ||
123 | $filename = 'sitemap.xml'; | 139 | $filename = 'sitemap.xml'; |
124 | 140 | ||
125 | setlocale(LC_ALL, 'ru_RU.CP1251'); | 141 | setlocale(LC_ALL, 'ru_RU.CP1251'); |
142 | + | ||
126 | $handle = fopen($dirName .'/'. $filename, "w"); | 143 | $handle = fopen($dirName .'/'. $filename, "w"); |
127 | 144 | ||
128 | $content = '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'; | 145 | $content = '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'; |
@@ -141,19 +158,20 @@ class SiteMapController extends Controller | @@ -141,19 +158,20 @@ class SiteMapController extends Controller | ||
141 | $this->createRow($url , 1,$content); | 158 | $this->createRow($url , 1,$content); |
142 | } | 159 | } |
143 | 160 | ||
144 | -// foreach ($this->getProducts() as $product) { | ||
145 | -// | ||
146 | -// $url = Url::to(['catalog/product', 'product' => $product]); | ||
147 | -// $this->createRow($url , 0.9, $content); | ||
148 | -// } | ||
149 | -// | ||
150 | -// foreach ($this->getArticles() as $article) { | ||
151 | -// | ||
152 | -// $url = Url::to(['articles/show', 'translit' => $article->translit, 'id' => $article->id,]); | ||
153 | -// $this->createRow($url , 0.8,$content); | ||
154 | -// | ||
155 | -// } | ||
156 | -// | 161 | + foreach ($this->getProducts() as $product) { |
162 | + | ||
163 | + $url = Url::to(['catalog/product', 'product' => $product]); | ||
164 | + $this->createRow($url , 0.9, $content); | ||
165 | + } | ||
166 | + | ||
167 | + foreach ($this->getArticles() as $article) { | ||
168 | + | ||
169 | + $url = Url::to(['articles/show', 'translit' => $article->translit, 'id' => $article->id,]); | ||
170 | + $this->createRow($url , 0.8,$content); | ||
171 | + | ||
172 | + } | ||
173 | + | ||
174 | + //brands | ||
157 | // foreach($this->getCategories() as $category) { | 175 | // foreach($this->getCategories() as $category) { |
158 | // foreach ($this->getBrands($category) as $brand) { | 176 | // foreach ($this->getBrands($category) as $brand) { |
159 | // if($this->checkFilter($category, ['brands' => [$brand->brand_id]])){ | 177 | // if($this->checkFilter($category, ['brands' => [$brand->brand_id]])){ |
@@ -163,6 +181,7 @@ class SiteMapController extends Controller | @@ -163,6 +181,7 @@ class SiteMapController extends Controller | ||
163 | // } | 181 | // } |
164 | // } | 182 | // } |
165 | // | 183 | // |
184 | +// //filters 1 lvl | ||
166 | // foreach($this->getCategories() as $category) { | 185 | // foreach($this->getCategories() as $category) { |
167 | // foreach ($this->getFilters($category) as $filter) { | 186 | // foreach ($this->getFilters($category) as $filter) { |
168 | // if($this->checkFilter($category, [$filter['group_alias'] => [$filter['option_alias']]])){ | 187 | // if($this->checkFilter($category, [$filter['group_alias'] => [$filter['option_alias']]])){ |
@@ -173,12 +192,14 @@ class SiteMapController extends Controller | @@ -173,12 +192,14 @@ class SiteMapController extends Controller | ||
173 | // } | 192 | // } |
174 | // } | 193 | // } |
175 | // | 194 | // |
195 | +// //seo links | ||
176 | // foreach($this->getSeoLinks() as $link) { | 196 | // foreach($this->getSeoLinks() as $link) { |
177 | // $url = Yii::$app->urlManager->baseUrl.$link->url; | 197 | // $url = Yii::$app->urlManager->baseUrl.$link->url; |
178 | // $this->createRow($url , 0.7, $content); | 198 | // $this->createRow($url , 0.7, $content); |
179 | // | 199 | // |
180 | // } | 200 | // } |
181 | // | 201 | // |
202 | +// //filters 2 lvl | ||
182 | // foreach($this->getCategories() as $category) { | 203 | // foreach($this->getCategories() as $category) { |
183 | // foreach ($this->getFilters($category) as $filter1) { | 204 | // foreach ($this->getFilters($category) as $filter1) { |
184 | // foreach ($this->getFilters($category) as $filter2) { | 205 | // foreach ($this->getFilters($category) as $filter2) { |