From 3d1a900d2413f04f0230e04ce1950f619a6a7c05 Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 15 Dec 2016 17:02:57 +0200 Subject: [PATCH] sitemap controller fix noindex --- console/controllers/SiteMapController.php | 47 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 34 insertions(+), 13 deletions(-) diff --git a/console/controllers/SiteMapController.php b/console/controllers/SiteMapController.php index db60556..962aebb 100644 --- a/console/controllers/SiteMapController.php +++ b/console/controllers/SiteMapController.php @@ -30,21 +30,28 @@ class SiteMapController extends Controller private $count = 1; public function getAddStatic() { + return [ 'http://www.rukzachok.com.ua', 'http://www.rukzachok.com.ua/catalog' ]; + } public function getStaticPages() { + return Page::find()->all(); + } public function getCategories() { + return Category::find()->andWhere(['meta_robots' => ''])->all(); + } public function checkFilter($category, $filter) { + $productModel = new ProductFrontendSearch(); $productProvider = $productModel->search($category, $filter); if(!empty($productProvider->models)){ @@ -52,19 +59,25 @@ class SiteMapController extends Controller } else { return false; } + } public function getProducts() { + return Product::find()->all(); } public function getSeoLinks() { + return Seo::find()->where(['meta' => ''])->all(); + } public function getArticles() { + return Articles::find()->all(); + } public function getBrands($category) { @@ -94,9 +107,11 @@ class SiteMapController extends Controller $this->urlList[] = $url; return true; } + } public function createRow( $url, $priority, &$content ) { + if($this->checkUrl($url)){ print $this->count++ . "\n"; $content .= '' . @@ -106,6 +121,7 @@ class SiteMapController extends Controller '' . $priority .'' . ''; } + } public function actionProcess() { @@ -123,6 +139,7 @@ class SiteMapController extends Controller $filename = 'sitemap.xml'; setlocale(LC_ALL, 'ru_RU.CP1251'); + $handle = fopen($dirName .'/'. $filename, "w"); $content = ''; @@ -141,19 +158,20 @@ class SiteMapController extends Controller $this->createRow($url , 1,$content); } -// foreach ($this->getProducts() as $product) { -// -// $url = Url::to(['catalog/product', 'product' => $product]); -// $this->createRow($url , 0.9, $content); -// } -// -// foreach ($this->getArticles() as $article) { -// -// $url = Url::to(['articles/show', 'translit' => $article->translit, 'id' => $article->id,]); -// $this->createRow($url , 0.8,$content); -// -// } -// + foreach ($this->getProducts() as $product) { + + $url = Url::to(['catalog/product', 'product' => $product]); + $this->createRow($url , 0.9, $content); + } + + foreach ($this->getArticles() as $article) { + + $url = Url::to(['articles/show', 'translit' => $article->translit, 'id' => $article->id,]); + $this->createRow($url , 0.8,$content); + + } + + //brands // foreach($this->getCategories() as $category) { // foreach ($this->getBrands($category) as $brand) { // if($this->checkFilter($category, ['brands' => [$brand->brand_id]])){ @@ -163,6 +181,7 @@ class SiteMapController extends Controller // } // } // +// //filters 1 lvl // foreach($this->getCategories() as $category) { // foreach ($this->getFilters($category) as $filter) { // if($this->checkFilter($category, [$filter['group_alias'] => [$filter['option_alias']]])){ @@ -173,12 +192,14 @@ class SiteMapController extends Controller // } // } // +// //seo links // foreach($this->getSeoLinks() as $link) { // $url = Yii::$app->urlManager->baseUrl.$link->url; // $this->createRow($url , 0.7, $content); // // } // +// //filters 2 lvl // foreach($this->getCategories() as $category) { // foreach ($this->getFilters($category) as $filter1) { // foreach ($this->getFilters($category) as $filter2) { -- libgit2 0.21.4