Commit 3d1a900d2413f04f0230e04ce1950f619a6a7c05

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