Commit 38ed47e1fe4abc74a7fd583846876a7ad9ce9041

Authored by Administrator
1 parent 8e889dc6

20.07.16

common/modules/product/helpers/ProductHelper.php
... ... @@ -190,6 +190,8 @@
190 190 */
191 191 public static function _setQueryParams(&$query, $params, $setPriceLimits = true)
192 192 {
  193 +// print_r($params);
  194 +// die();
193 195 if(!empty( $params[ 'keywords' ] )) {
194 196 if(!is_array($params[ 'keywords' ])) {
195 197 $params[ 'keywords' ] = [ $params[ 'keywords' ] ];
... ...
common/modules/product/models/Category.php
... ... @@ -152,6 +152,14 @@ class Category extends \yii\db\ActiveRecord
152 152 return $this->hasMany(CategoryName::className(), ['category_id' => 'category_id']);
153 153 }
154 154  
  155 +
  156 + public function getBrands(){
  157 + return $this->getProducts()->select('brand.*')->joinWith('brand')->groupBy('brand.brand_id');
  158 +
  159 + }
  160 +
  161 +
  162 +
155 163 /**
156 164 * @return \yii\db\ActiveQuery
157 165 */
... ...
console/config/main.php
... ... @@ -12,6 +12,12 @@ return [
12 12 'bootstrap' => ['log'],
13 13 'controllerNamespace' => 'console\controllers',
14 14 'components' => [
  15 + 'urlManager' => [
  16 + 'baseUrl' => 'http://www.rukzachok.com.ua',
  17 + 'enablePrettyUrl' => true,
  18 + 'showScriptName' => false,
  19 +
  20 + ],
15 21 'log' => [
16 22 'targets' => [
17 23 [
... ...
console/controllers/SiteMapController.php 0 → 100644
  1 +<?php
  2 +
  3 +namespace console\controllers;
  4 +
  5 +use common\models\Articles;
  6 +use common\models\Seo;
  7 +use common\modules\product\helpers\FilterHelper;
  8 +use common\modules\product\models\Brand;
  9 +use common\modules\product\models\Category;
  10 +use common\modules\product\models\Product;
  11 +use frontend\models\ProductFrontendSearch;
  12 +use Yii;
  13 +use common\models\Page;
  14 +use common\models\PageSearch;
  15 +use yii\helpers\ArrayHelper;
  16 +use yii\helpers\Url;
  17 +use yii\console\Controller;
  18 +use yii\web\NotFoundHttpException;
  19 +use yii\filters\VerbFilter;
  20 +use developeruz\db_rbac\behaviors\AccessBehavior;
  21 +/**
  22 + * PageController implements the CRUD actions for Page model.
  23 + */
  24 +class SiteMapController extends Controller
  25 +{
  26 +
  27 + private $urlList = ['http://www.rukzachok.com.ua/'];
  28 + private $count = 1;
  29 +
  30 +
  31 +
  32 + public function checkFilter($category, $filter){
  33 + $productModel = new ProductFrontendSearch();
  34 + $productProvider = $productModel->search($category, $filter);
  35 + if(!empty($productProvider->models)){
  36 + return true;
  37 + } else {
  38 + return false;
  39 + }
  40 + }
  41 +
  42 +
  43 +
  44 + public function getAddStatic(){
  45 + return [
  46 + 'http://www.rukzachok.com.ua',
  47 + 'http://www.rukzachok.com.ua/catalog'
  48 + ];
  49 + }
  50 +
  51 +
  52 + public function getProducts() {
  53 + return Product::find()->all();
  54 +
  55 + }
  56 +
  57 +
  58 + public function getSeoLinks() {
  59 + return Seo::find()->where(['meta' => ''])->all();
  60 +
  61 + }
  62 +
  63 + public function getStaticPages(){
  64 + return Page::find()->all();
  65 + }
  66 +
  67 +
  68 + public function getCategories(){
  69 + return Category::find()->all();
  70 + }
  71 +
  72 +
  73 + public function getArticles(){
  74 + return Articles::find()->all();
  75 + }
  76 +
  77 + public function getBrands($category){
  78 +
  79 + return $category->brands;
  80 + }
  81 +
  82 + public function getFilters($category){
  83 +
  84 + return $category->getActiveFilters()->all();
  85 +
  86 + }
  87 +
  88 +
  89 + public function checkUrl($url){
  90 + if(!in_array($url, $this->urlList)){
  91 + $this->urlList[] = $url;
  92 + return true;
  93 + } else {
  94 + return false;
  95 + }
  96 + }
  97 +
  98 +
  99 + public function createRow( $url, $priority, &$content ){
  100 + if($this->checkUrl($url)){
  101 + print $this->count++ . "\n";
  102 + $content .= '<url>' .
  103 + '<loc>' . $url . '</loc>' .
  104 + '<lastmod>' . date('Y-m-d') . '</lastmod>' .
  105 + '<changefreq>Daily</changefreq>' .
  106 + '<priority>' . $priority .'</priority>' .
  107 + '</url>';
  108 + }
  109 + }
  110 +
  111 +
  112 + public function actionProcess() {
  113 +
  114 + $config = ArrayHelper::merge(
  115 + require(__DIR__ . '/../../frontend/config/main.php'),
  116 + require(__DIR__ . '/../../common/config/main.php')
  117 +
  118 + );
  119 +
  120 + Yii::$app->urlManager->addRules($config['components']['urlManager']['rules']);
  121 +
  122 +
  123 +
  124 + $dirName = Yii::getAlias('@uploadDir');
  125 +
  126 + $filename = 'sitemap_'. date('d_m_Y_H_i') .'.xml';
  127 +
  128 + setlocale(LC_ALL, 'ru_RU.CP1251');
  129 + $handle = fopen($dirName .'/'. $filename, "w");
  130 +
  131 + $content = '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';
  132 +
  133 + foreach ($this->getAddStatic() as $page) {
  134 + $url = Url::to(['text/index','translit' => $page->translit]);
  135 + $this->createRow($url , 1,$content);
  136 + }
  137 +
  138 + foreach ($this->getStaticPages() as $page) {
  139 + $url = Url::to(['text/index','translit' => $page->translit]);
  140 + $this->createRow($url , 1,$content);
  141 + }
  142 +
  143 + foreach ($this->getCategories() as $category) {
  144 + $url = Url::to(['catalog/category', 'category' => $category]);
  145 + $this->createRow($url , 1,$content);
  146 + }
  147 +
  148 +
  149 + foreach ($this->getProducts() as $product) {
  150 +
  151 + $url = Url::to(['catalog/product', 'product' => $product]);
  152 + $this->createRow($url , 0.9, $content);
  153 + }
  154 +
  155 +
  156 + foreach ($this->getArticles() as $article) {
  157 +
  158 + $url = Url::to(['articles/show', 'translit' => $article->translit, 'id' => $article->id,]);
  159 + $this->createRow($url , 0.8,$content);
  160 +
  161 + }
  162 +
  163 +
  164 + foreach($this->getCategories() as $category){
  165 + foreach ($this->getBrands($category) as $brand) {
  166 + if($this->checkFilter($category, ['brands' => [$brand->brand_id]])){
  167 + $url = Url::to(['catalog/category', 'category' => $category, 'filters' => ['brands' => [$brand->alias]]]) ;
  168 + $this->createRow($url , 0.8, $content);
  169 + }
  170 + }
  171 + }
  172 +
  173 +
  174 + foreach($this->getCategories() as $category){
  175 + foreach ($this->getFilters($category) as $filter) {
  176 + if($this->checkFilter($category, [$filter['group_alias'] => [$filter['option_alias']]])){
  177 + $url = Url::to(['catalog/category', 'category' => $category, 'filters' => [$filter['group_alias'] => [$filter['option_alias']]] ]);
  178 + $this->createRow($url , 0.8, $content);
  179 + }
  180 +
  181 + }
  182 + }
  183 +
  184 + foreach($this->getSeoLinks() as $link){
  185 + $url = Yii::$app->urlManager->baseUrl.$link->url;
  186 + $this->createRow($url , 0.7, $content);
  187 +
  188 + }
  189 +
  190 +
  191 +
  192 +// foreach($this->getCategories() as $category){
  193 +// foreach ($this->getFilters($category) as $filter1) {
  194 +// foreach ($this->getFilters($category) as $filter2) {
  195 +// if($this->checkFilter($category, [$filter1['group_alias'] => [$filter1['option_alias']],$filter2['group_alias'] => [$filter2['option_alias']]] )){
  196 +// $url = Url::to(['catalog/category', 'category' => $category, 'filters' => [$filter1['group_alias'] => [$filter1['option_alias']],$filter2['group_alias'] => [$filter2['option_alias']]] ]);
  197 +// $this->createRow($url , 0.7, $content);
  198 +// }
  199 +//
  200 +// }
  201 +//
  202 +// foreach ($this->getBrands($category) as $brand) {
  203 +// if($this->checkFilter($category, ['brands' => [$brand->brand_id], $filter1['group_alias'] => [$filter1['option_alias']]] )){
  204 +// $url = Url::to(['catalog/category', 'category' => $category, 'filters' => ['brands' => [$brand->alias],$filter1['group_alias'] => [$filter1['option_alias']]]]);
  205 +// $this->createRow($url , 0.7,$content);
  206 +// }
  207 +//
  208 +// }
  209 +// }
  210 +// }
  211 +
  212 +
  213 +
  214 + $content .= '</urlset>';
  215 +
  216 + fwrite($handle, $content);
  217 + fclose($handle);
  218 +
  219 + print $dirName .'/'. $filename;
  220 + }
  221 +
  222 +}
... ...
frontend/views/basket/index.php
... ... @@ -190,4 +190,5 @@ $(&#39;#orders-delivery input[type=\&quot;radio\&quot;]&#39;).click(function(){
190 190 <?php ActiveForm::end(); ?>
191 191  
192 192  
193   -</div>
194 193 \ No newline at end of file
  194 +</div>
  195 +
... ...
frontend/views/catalog/products.php
... ... @@ -2,28 +2,34 @@
2 2  
3 3 /** @var $this \yii\web\View */
4 4 /** @var $productProvider \yii\data\ActiveDataProvider */
5   -
  5 +
  6 + use common\modules\product\models\Product;
6 7 use yii\helpers\ArrayHelper;
7   - use yii\helpers\Url;
8   -use yii\widgets\Breadcrumbs;
9   -use yii\web\View;
10   -use common\modules\product\helpers\ProductHelper;
11   -use common\modules\product\helpers\FilterHelper;
12   -use frontend\widgets\Seo;
13   -//$this->title = $category->categoryName->value;
14   -$this->params['seo']['title'] = !empty($category->meta_title) ? $category->meta_title : '';
15   -
16   -$this->params['seo']['fields']['meta-title'] = $category->meta_title;
17   -$this->params['seo']['h1'] = !empty($category->h1) ? $category->h1 : $category->name;
18   -$this->params['seo']['seo_text'] = $category->seo_text;
19   -$this->params['seo']['description'] = $category->meta_desc;
20   -$this->params['seo']['meta'] = $category->meta_robots;
21   -$this->params['seo']['category_name'] = $category->name;
22   -//foreach($category->getParents()->all() as $parent) {
23   -// $this->params['breadcrumbs'][] = ['label' => $parent->categoryName->value, 'url' => ['catalog/category', 'category' => $parent]];
24   -//}
25   -$this->params['breadcrumbs'][] = ['label' => 'Каталог', 'url' => Url::to(['catalog/category']),'itemprop' => 'url', ];
26   -$this->params['breadcrumbs'][] = $category->categoryName->value;
  8 + use yii\helpers\Url;
  9 + use yii\widgets\Breadcrumbs;
  10 + use yii\web\View;
  11 + use common\modules\product\helpers\ProductHelper;
  12 + use common\modules\product\helpers\FilterHelper;
  13 + use frontend\widgets\Seo;
  14 + //$this->title = $category->categoryName->value;
  15 + $this->params['seo']['title'] = !empty($category->meta_title) ? $category->meta_title : '';
  16 +
  17 + if(empty($productProvider->models)){
  18 + $this->params['seo']['meta'] = 'noindex,nofollow';
  19 + }else{
  20 + $this->params['seo']['meta'] = $category->meta_robots;
  21 + }
  22 + $this->params['seo']['fields']['meta-title'] = $category->meta_title;
  23 + $this->params['seo']['h1'] = !empty($category->h1) ? $category->h1 : $category->name;
  24 + $this->params['seo']['seo_text'] = $category->seo_text;
  25 + $this->params['seo']['description'] = $category->meta_desc;
  26 +
  27 + $this->params['seo']['category_name'] = $category->name;
  28 + //foreach($category->getParents()->all() as $parent) {
  29 + // $this->params['breadcrumbs'][] = ['label' => $parent->categoryName->value, 'url' => ['catalog/category', 'category' => $parent]];
  30 + //}
  31 + $this->params['breadcrumbs'][] = ['label' => 'Каталог', 'url' => Url::to(['catalog/category']),'itemprop' => 'url', ];
  32 + $this->params['breadcrumbs'][] = $category->categoryName->value;
27 33  
28 34  
29 35 $this->registerCssFile (Yii::getAlias('@web/css/ion.rangeSlider.css'));
... ...