From 9580e5482327795294b95a11ab704470ec950a5a Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 1 Dec 2016 22:26:15 +0200 Subject: [PATCH] -Site map in progress. Need to split --- console/SiteMapController.php | 172 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------------------------------------------- 1 file changed, 108 insertions(+), 64 deletions(-) diff --git a/console/SiteMapController.php b/console/SiteMapController.php index 026ac3e..61f4498 100755 --- a/console/SiteMapController.php +++ b/console/SiteMapController.php @@ -2,6 +2,9 @@ namespace artweb\artbox\ecommerce\console; + use artweb\artbox\ecommerce\models\Brand; + use artweb\artbox\ecommerce\models\ProductVariant; + use artweb\artbox\language\models\Language; use artweb\artbox\seo\models\Seo; use artweb\artbox\ecommerce\models\Category; use artweb\artbox\ecommerce\models\Product; @@ -18,7 +21,7 @@ class SiteMapController extends Controller { - private $urlList = [ 'http://www.rukzachok.com.ua/' ]; + private $urlList = [ 'https://dev.extremstyle.ua/ru' ]; private $count = 1; public function checkFilter($category, $filter) @@ -35,15 +38,16 @@ public function getAddStatic() { return [ - 'http://www.rukzachok.com.ua', - 'http://www.rukzachok.com.ua/catalog', + 'https://dev.extremstyle.ua/ru', ]; } - public function getProducts() + public function getVariants() { - return Product::find() - ->all(); + return ProductVariant::find() + ->with('lang') + ->with('product.lang') + ->batch(1000); } @@ -58,19 +62,32 @@ public function getStaticPages() { return Page::find() + ->with('lang') ->all(); } public function getCategories() { return Category::find() + ->with('lang') ->all(); } - public function getBrands($category) + public function getCategoriesWithFilters() { - - return $category->brands; + return Category::find() + ->with('lang') + ->joinWith('taxGroups.lang') + ->with('taxGroups.taxOptions.lang') + ->where(['tax_group.meta_robots' => '',]) + ->all(); + } + + public function getBrands() + { + return Brand::find() + ->joinWith('lang') + ->all(); } /** @@ -81,8 +98,13 @@ public function getFilters($category) { - return $category->getActiveFilters() + ->andWhere( + [ + + 'tax_group.meta_robots' => '', + ] + ) ->all(); } @@ -100,16 +122,15 @@ public function createRow($url, $priority, &$content) { if ($this->checkUrl($url)) { - print $this->count++ . "\n"; + print $this->count++ . $url . "\n"; $content .= '' . '' . $url . '' . '' . date( 'Y-m-d' - ) . '' . 'Daily' . '' . $priority . '' . ''; + ) . '' . 'Weekly' . '' . $priority . '' . ''; } } public function actionProcess() { - $config = ArrayHelper::merge( require( \Yii::getAlias('@frontend/config/') . 'main.php' ), require( \Yii::getAlias('@common/config/') . 'main.php' ) @@ -119,8 +140,7 @@ $dirName = Yii::getAlias('@frontend') . '/web'; - $filename = 'sitemap.xml'; - + $filename = 'test_sitemap.xml'; setlocale(LC_ALL, 'ru_RU.CP1251'); $handle = fopen($dirName . '/' . $filename, "w"); @@ -133,8 +153,8 @@ foreach ($this->getStaticPages() as $page) { $url = Url::to( [ - 'text/index', - 'translit' => $page->translit, + 'site/page', + 'slug' => $page->lang->alias, ] ); $this->createRow($url, 1, $content); @@ -144,53 +164,45 @@ $url = Url::to( [ 'catalog/category', - 'category' => $category, + 'category' => $category->lang->alias, ] ); - $this->createRow($url, 1, $content); + $this->createRow($url, 0.8, $content); + } + + foreach ($this->getVariants() as $rows) { + foreach ($rows as $row) { + $url = Url::to( + [ + 'catalog/product', + 'product' => $row->product->lang->alias, + 'variant' => $row->sku, + ] + ); + $this->createRow($url, 0.9, $content); + } } - foreach ($this->getProducts() as $product) { - + foreach ($this->getBrands() as $brand) { + $url = Url::to( [ - 'catalog/product', - 'product' => $product, + 'brand/view', + 'slug' => $brand->lang->alias, ] ); - $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->getCategories() as $category) { - foreach ($this->getBrands($category) as $brand) { - if ($this->checkFilter($category, [ 'brands' => [ $brand->id ] ])) { - $url = Url::to( - [ - 'catalog/category', - 'category' => $category, - 'filters' => [ 'brands' => [ $brand->alias ] ], - ] - ); - $this->createRow($url, 0.8, $content); - } - } + $this->createRow($url, 0.7, $content); + } - foreach ($this->getCategories() as $category) { - foreach ($this->getFilters($category) as $filter) { - if ($this->checkFilter($category, [ $filter[ 'group_alias' ] => [ $filter[ 'option_alias' ] ] ])) { + foreach ($this->getCategoriesWithFilters() as $category) { + foreach ($category->taxGroups as $group) { + foreach ($group->taxOptions as $option) { $url = Url::to( [ 'catalog/category', 'category' => $category, - 'filters' => [ $filter[ 'group_alias' ] => [ $filter[ 'option_alias' ] ] ], + 'filters' => [ $group->lang->alias => [ $option->lang->alias ] ], ] ); $this->createRow($url, 0.8, $content); @@ -202,28 +214,60 @@ foreach ($this->getSeoLinks() as $link) { $url = Yii::$app->urlManager->baseUrl . $link->url; $this->createRow($url, 0.7, $content); - + } - // foreach($this->getCategories() as $category){ - // foreach ($this->getFilters($category) as $filter1) { - // foreach ($this->getFilters($category) as $filter2) { - // if($this->checkFilter($category, [$filter1['group_alias'] => [$filter1['option_alias']],$filter2['group_alias'] => [$filter2['option_alias']]] )){ - // $url = Url::to(['catalog/category', 'category' => $category, 'filters' => [$filter1['group_alias'] => [$filter1['option_alias']],$filter2['group_alias'] => [$filter2['option_alias']]] ]); - // $this->createRow($url , 0.7, $content); + // foreach ($this->getCategories() as $category) { + // foreach ($this->getFilters($category) as $filter1) { + // foreach ($this->getFilters($category) as $filter2) { + // if ($this->checkFilter( + // $category, + // [ + // $filter1[ 'group_alias' ] => [ $filter1[ 'option_alias' ] ], + // $filter2[ 'group_alias' ] => [ $filter2[ 'option_alias' ] ], + // ] + // ) + // ) { + // $url = Url::to( + // [ + // 'catalog/category', + // 'category' => $category, + // 'filters' => [ + // $filter1[ 'group_alias' ] => [ $filter1[ 'option_alias' ] ], + // $filter2[ 'group_alias' ] => [ $filter2[ 'option_alias' ] ], + // ], + // ] + // ); + // $this->createRow($url, 0.7, $content); + // } + // // } // - // } + // foreach ($this->getBrands($category) as $brand) { + // if ($this->checkFilter( + // $category, + // [ + // 'brands' => [ $brand->id ], + // $filter1[ 'group_alias' ] => [ $filter1[ 'option_alias' ] ], + // ] + // ) + // ) { + // $url = Url::to( + // [ + // 'catalog/category', + // 'category' => $category, + // 'filters' => [ + // 'brands' => [ $brand->alias ], + // $filter1[ 'group_alias' ] => [ $filter1[ 'option_alias' ] ], + // ], + // ] + // ); + // $this->createRow($url, 0.7, $content); + // } // - // foreach ($this->getBrands($category) as $brand) { - // if($this->checkFilter($category, ['brands' => [$brand->id], $filter1['group_alias'] => [$filter1['option_alias']]] )){ - // $url = Url::to(['catalog/category', 'category' => $category, 'filters' => ['brands' => [$brand->alias],$filter1['group_alias'] => [$filter1['option_alias']]]]); - // $this->createRow($url , 0.7,$content); // } - // // } // } - // } $content .= ''; -- libgit2 0.21.4