diff --git a/common/modules/product/helpers/ProductHelper.php b/common/modules/product/helpers/ProductHelper.php index 3132b60..08420f7 100755 --- a/common/modules/product/helpers/ProductHelper.php +++ b/common/modules/product/helpers/ProductHelper.php @@ -190,6 +190,8 @@ */ public static function _setQueryParams(&$query, $params, $setPriceLimits = true) { +// print_r($params); +// die(); if(!empty( $params[ 'keywords' ] )) { if(!is_array($params[ 'keywords' ])) { $params[ 'keywords' ] = [ $params[ 'keywords' ] ]; diff --git a/common/modules/product/models/Category.php b/common/modules/product/models/Category.php index c3dc4de..233a413 100755 --- a/common/modules/product/models/Category.php +++ b/common/modules/product/models/Category.php @@ -152,6 +152,14 @@ class Category extends \yii\db\ActiveRecord return $this->hasMany(CategoryName::className(), ['category_id' => 'category_id']); } + + public function getBrands(){ + return $this->getProducts()->select('brand.*')->joinWith('brand')->groupBy('brand.brand_id'); + + } + + + /** * @return \yii\db\ActiveQuery */ diff --git a/console/config/main.php b/console/config/main.php index 992885a..d547bde 100755 --- a/console/config/main.php +++ b/console/config/main.php @@ -12,6 +12,12 @@ return [ 'bootstrap' => ['log'], 'controllerNamespace' => 'console\controllers', 'components' => [ + 'urlManager' => [ + 'baseUrl' => 'http://www.rukzachok.com.ua', + 'enablePrettyUrl' => true, + 'showScriptName' => false, + + ], 'log' => [ 'targets' => [ [ diff --git a/console/controllers/SiteMapController.php b/console/controllers/SiteMapController.php new file mode 100644 index 0000000..7a5950a --- /dev/null +++ b/console/controllers/SiteMapController.php @@ -0,0 +1,222 @@ +search($category, $filter); + if(!empty($productProvider->models)){ + return true; + } else { + return false; + } + } + + + + public function getAddStatic(){ + return [ + 'http://www.rukzachok.com.ua', + 'http://www.rukzachok.com.ua/catalog' + ]; + } + + + public function getProducts() { + return Product::find()->all(); + + } + + + public function getSeoLinks() { + return Seo::find()->where(['meta' => ''])->all(); + + } + + public function getStaticPages(){ + return Page::find()->all(); + } + + + public function getCategories(){ + return Category::find()->all(); + } + + + public function getArticles(){ + return Articles::find()->all(); + } + + public function getBrands($category){ + + return $category->brands; + } + + public function getFilters($category){ + + return $category->getActiveFilters()->all(); + + } + + + public function checkUrl($url){ + if(!in_array($url, $this->urlList)){ + $this->urlList[] = $url; + return true; + } else { + return false; + } + } + + + public function createRow( $url, $priority, &$content ){ + if($this->checkUrl($url)){ + print $this->count++ . "\n"; + $content .= '' . + '' . $url . '' . + '' . date('Y-m-d') . '' . + 'Daily' . + '' . $priority .'' . + ''; + } + } + + + public function actionProcess() { + + $config = ArrayHelper::merge( + require(__DIR__ . '/../../frontend/config/main.php'), + require(__DIR__ . '/../../common/config/main.php') + + ); + + Yii::$app->urlManager->addRules($config['components']['urlManager']['rules']); + + + + $dirName = Yii::getAlias('@uploadDir'); + + $filename = 'sitemap_'. date('d_m_Y_H_i') .'.xml'; + + setlocale(LC_ALL, 'ru_RU.CP1251'); + $handle = fopen($dirName .'/'. $filename, "w"); + + $content = ''; + + foreach ($this->getAddStatic() as $page) { + $url = Url::to(['text/index','translit' => $page->translit]); + $this->createRow($url , 1,$content); + } + + foreach ($this->getStaticPages() as $page) { + $url = Url::to(['text/index','translit' => $page->translit]); + $this->createRow($url , 1,$content); + } + + foreach ($this->getCategories() as $category) { + $url = Url::to(['catalog/category', 'category' => $category]); + $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->getCategories() as $category){ + foreach ($this->getBrands($category) as $brand) { + if($this->checkFilter($category, ['brands' => [$brand->brand_id]])){ + $url = Url::to(['catalog/category', 'category' => $category, 'filters' => ['brands' => [$brand->alias]]]) ; + $this->createRow($url , 0.8, $content); + } + } + } + + + foreach($this->getCategories() as $category){ + foreach ($this->getFilters($category) as $filter) { + if($this->checkFilter($category, [$filter['group_alias'] => [$filter['option_alias']]])){ + $url = Url::to(['catalog/category', 'category' => $category, 'filters' => [$filter['group_alias'] => [$filter['option_alias']]] ]); + $this->createRow($url , 0.8, $content); + } + + } + } + + 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->getBrands($category) as $brand) { +// if($this->checkFilter($category, ['brands' => [$brand->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 .= ''; + + fwrite($handle, $content); + fclose($handle); + + print $dirName .'/'. $filename; + } + +} diff --git a/frontend/views/basket/index.php b/frontend/views/basket/index.php index 89fce9f..ae53a56 100755 --- a/frontend/views/basket/index.php +++ b/frontend/views/basket/index.php @@ -190,4 +190,5 @@ $('#orders-delivery input[type=\"radio\"]').click(function(){ - \ No newline at end of file + + diff --git a/frontend/views/catalog/products.php b/frontend/views/catalog/products.php index d1ec4c3..15cd2ce 100755 --- a/frontend/views/catalog/products.php +++ b/frontend/views/catalog/products.php @@ -2,28 +2,34 @@ /** @var $this \yii\web\View */ /** @var $productProvider \yii\data\ActiveDataProvider */ - + + use common\modules\product\models\Product; use yii\helpers\ArrayHelper; - use yii\helpers\Url; -use yii\widgets\Breadcrumbs; -use yii\web\View; -use common\modules\product\helpers\ProductHelper; -use common\modules\product\helpers\FilterHelper; -use frontend\widgets\Seo; -//$this->title = $category->categoryName->value; -$this->params['seo']['title'] = !empty($category->meta_title) ? $category->meta_title : ''; - -$this->params['seo']['fields']['meta-title'] = $category->meta_title; -$this->params['seo']['h1'] = !empty($category->h1) ? $category->h1 : $category->name; -$this->params['seo']['seo_text'] = $category->seo_text; -$this->params['seo']['description'] = $category->meta_desc; -$this->params['seo']['meta'] = $category->meta_robots; -$this->params['seo']['category_name'] = $category->name; -//foreach($category->getParents()->all() as $parent) { -// $this->params['breadcrumbs'][] = ['label' => $parent->categoryName->value, 'url' => ['catalog/category', 'category' => $parent]]; -//} -$this->params['breadcrumbs'][] = ['label' => 'Каталог', 'url' => Url::to(['catalog/category']),'itemprop' => 'url', ]; -$this->params['breadcrumbs'][] = $category->categoryName->value; + use yii\helpers\Url; + use yii\widgets\Breadcrumbs; + use yii\web\View; + use common\modules\product\helpers\ProductHelper; + use common\modules\product\helpers\FilterHelper; + use frontend\widgets\Seo; + //$this->title = $category->categoryName->value; + $this->params['seo']['title'] = !empty($category->meta_title) ? $category->meta_title : ''; + + if(empty($productProvider->models)){ + $this->params['seo']['meta'] = 'noindex,nofollow'; + }else{ + $this->params['seo']['meta'] = $category->meta_robots; + } + $this->params['seo']['fields']['meta-title'] = $category->meta_title; + $this->params['seo']['h1'] = !empty($category->h1) ? $category->h1 : $category->name; + $this->params['seo']['seo_text'] = $category->seo_text; + $this->params['seo']['description'] = $category->meta_desc; + + $this->params['seo']['category_name'] = $category->name; + //foreach($category->getParents()->all() as $parent) { + // $this->params['breadcrumbs'][] = ['label' => $parent->categoryName->value, 'url' => ['catalog/category', 'category' => $parent]]; + //} + $this->params['breadcrumbs'][] = ['label' => 'Каталог', 'url' => Url::to(['catalog/category']),'itemprop' => 'url', ]; + $this->params['breadcrumbs'][] = $category->categoryName->value; $this->registerCssFile (Yii::getAlias('@web/css/ion.rangeSlider.css')); -- libgit2 0.21.4