Commit 74d06b0fad9fe4ba595d66c7aa6f4d9fbe28f188
1 parent
6c673f5d
-Site map generation fixed
Showing
3 changed files
with
473 additions
and
365 deletions
Show diff stats
common/modules/rubrication/models/TaxGroup.php
| 1 | <?php | 1 | <?php |
| 2 | - | ||
| 3 | -namespace common\modules\rubrication\models; | ||
| 4 | - | ||
| 5 | -use common\modules\product\models\Category; | ||
| 6 | -use Yii; | ||
| 7 | - | ||
| 8 | -/** | ||
| 9 | - * This is the model class for table "{{%tax_group}}". | ||
| 10 | - * | ||
| 11 | - * @property integer $tax_group_id | ||
| 12 | - * @property string $alias | ||
| 13 | - * @property string $name | ||
| 14 | - * @property string $description | ||
| 15 | - * @property string $module | ||
| 16 | - * @property boolean $hierarchical | ||
| 17 | - * @property string $settings | ||
| 18 | - * @property boolean $is_filter | ||
| 19 | - * @property integer $level | ||
| 20 | - * @property integer $sort | ||
| 21 | - * @property boolean $display | ||
| 22 | - * @property boolean $is_menu | ||
| 23 | - * @property boolean $use_in_name | ||
| 24 | - * @property TaxGroupToGroup[] $taxGroupToGroups | ||
| 25 | - * @property TaxGroupToGroup[] $taxGroupToGroups0 | ||
| 26 | - * @property TaxOption[] $taxOptions | ||
| 27 | - */ | ||
| 28 | -class TaxGroup extends \yii\db\ActiveRecord | ||
| 29 | -{ | ||
| 30 | - public $_options = []; | ||
| 31 | - | 2 | + |
| 3 | + namespace common\modules\rubrication\models; | ||
| 4 | + | ||
| 5 | + use common\modules\product\models\Category; | ||
| 6 | + use Yii; | ||
| 7 | + use yii\db\ActiveQuery; | ||
| 8 | + | ||
| 32 | /** | 9 | /** |
| 33 | - * @inheritdoc | 10 | + * This is the model class for table "{{%tax_group}}". |
| 11 | + * | ||
| 12 | + * @property integer $tax_group_id | ||
| 13 | + * @property string $alias | ||
| 14 | + * @property string $name | ||
| 15 | + * @property string $description | ||
| 16 | + * @property Category $category | ||
| 17 | + * @property string $module | ||
| 18 | + * @property boolean $hierarchical | ||
| 19 | + * @property string $settings | ||
| 20 | + * @property boolean $is_filter | ||
| 21 | + * @property integer $level | ||
| 22 | + * @property integer $sort | ||
| 23 | + * @property boolean $display | ||
| 24 | + * @property boolean $is_menu | ||
| 25 | + * @property boolean $use_in_name | ||
| 26 | + * @property TaxGroupToGroup[] $taxGroupToGroups | ||
| 27 | + * @property TaxGroupToGroup[] $taxGroupToGroups0 | ||
| 28 | + * @property TaxOption[] $taxOptions | ||
| 34 | */ | 29 | */ |
| 35 | - public function behaviors() | 30 | + class TaxGroup extends \yii\db\ActiveRecord |
| 36 | { | 31 | { |
| 37 | - return [ | ||
| 38 | - 'slug' => [ | ||
| 39 | - 'class' => 'common\behaviors\Slug', | ||
| 40 | - 'in_attribute' => 'name', | ||
| 41 | - 'out_attribute' => 'alias', | ||
| 42 | - 'translit' => true | ||
| 43 | - ], | ||
| 44 | - ]; | ||
| 45 | - } | ||
| 46 | - | ||
| 47 | - /** | ||
| 48 | - * @inheritdoc | ||
| 49 | - */ | ||
| 50 | - public static function tableName() | ||
| 51 | - { | ||
| 52 | - return 'tax_group'; | ||
| 53 | - } | ||
| 54 | - | ||
| 55 | - /** | ||
| 56 | - * @inheritdoc | ||
| 57 | - */ | ||
| 58 | - public function rules() | ||
| 59 | - { | ||
| 60 | - return [ | ||
| 61 | - [['name', 'module'], 'required'], | ||
| 62 | - [['description', 'settings'], 'string'], | ||
| 63 | - [['hierarchical', 'is_filter', 'display','is_menu', 'use_in_name'], 'boolean'], | ||
| 64 | - [['level', 'sort'], 'integer'], | ||
| 65 | - [['alias', 'module'], 'string', 'max' => 50], | ||
| 66 | - [['name'], 'string', 'max' => 255], | ||
| 67 | - [['categories'], 'safe'], | ||
| 68 | - [['use_in_name'], 'default', 'value' => false], | ||
| 69 | - ]; | ||
| 70 | - } | ||
| 71 | - | ||
| 72 | - /** | ||
| 73 | - * @inheritdoc | ||
| 74 | - */ | ||
| 75 | - public function attributeLabels() | ||
| 76 | - { | ||
| 77 | - return [ | ||
| 78 | - 'tax_group_id' => 'Tax Group ID', | ||
| 79 | - 'alias' => 'Alias', | ||
| 80 | - 'name' => 'Name', | ||
| 81 | - 'description' => 'Description', | ||
| 82 | - 'module' => 'Module', | ||
| 83 | - 'hierarchical' => 'Hierarchical', | ||
| 84 | -// 'settings' => 'Settings', | ||
| 85 | - 'is_filter' => 'Use in filter', | ||
| 86 | - 'sort' => 'Sort', | ||
| 87 | - 'display' => 'Display', | ||
| 88 | - 'is_menu' => 'ะัะพะฑัะฐะถะฐัั ะฒ ะผะตะฝั', | ||
| 89 | - 'use_in_name' => 'ะัะฟะพะปัะทะพะฒะฐัั ะฒ ะฝะฐะทะฒะฐะฝะธะธ', | ||
| 90 | - ]; | ||
| 91 | - } | ||
| 92 | - | ||
| 93 | - /** | ||
| 94 | - * @return \yii\db\ActiveQuery | ||
| 95 | - */ | ||
| 96 | - public function getTaxGroupToGroups() | ||
| 97 | - { | ||
| 98 | - return $this->hasMany(TaxGroupToGroup::className(), ['tax_group1_id' => 'tax_group_id'])->inverseOf('taxGroup1'); | ||
| 99 | - } | ||
| 100 | - | ||
| 101 | - public function getCategories() | ||
| 102 | - { | ||
| 103 | - return $this->hasMany(Category::className(), ['category_id' => 'category_id']) | ||
| 104 | - ->viaTable('tax_group_to_category', ['tax_group_id' => 'tax_group_id']); | ||
| 105 | - } | ||
| 106 | - | ||
| 107 | - public function setCategories($values) | ||
| 108 | - { | ||
| 109 | - $this->categories = $values; | ||
| 110 | - } | ||
| 111 | - | ||
| 112 | - public function afterSave($insert, $changedAttributes) | ||
| 113 | - { | ||
| 114 | - | ||
| 115 | - $this->unlinkAll('categories',true); | ||
| 116 | - $categories = Category::findAll($this->categories); | ||
| 117 | - foreach($categories as $category){ | ||
| 118 | - $this->link('categories', $category); | 32 | + public $_options = []; |
| 33 | + | ||
| 34 | + /** | ||
| 35 | + * @inheritdoc | ||
| 36 | + */ | ||
| 37 | + public function behaviors() | ||
| 38 | + { | ||
| 39 | + return [ | ||
| 40 | + 'slug' => [ | ||
| 41 | + 'class' => 'common\behaviors\Slug', | ||
| 42 | + 'in_attribute' => 'name', | ||
| 43 | + 'out_attribute' => 'alias', | ||
| 44 | + 'translit' => true, | ||
| 45 | + ], | ||
| 46 | + ]; | ||
| 47 | + } | ||
| 48 | + | ||
| 49 | + /** | ||
| 50 | + * @inheritdoc | ||
| 51 | + */ | ||
| 52 | + public static function tableName() | ||
| 53 | + { | ||
| 54 | + return 'tax_group'; | ||
| 55 | + } | ||
| 56 | + | ||
| 57 | + /** | ||
| 58 | + * @inheritdoc | ||
| 59 | + */ | ||
| 60 | + public function rules() | ||
| 61 | + { | ||
| 62 | + return [ | ||
| 63 | + [ | ||
| 64 | + [ | ||
| 65 | + 'name', | ||
| 66 | + 'module', | ||
| 67 | + ], | ||
| 68 | + 'required', | ||
| 69 | + ], | ||
| 70 | + [ | ||
| 71 | + [ | ||
| 72 | + 'description', | ||
| 73 | + 'settings', | ||
| 74 | + ], | ||
| 75 | + 'string', | ||
| 76 | + ], | ||
| 77 | + [ | ||
| 78 | + [ | ||
| 79 | + 'hierarchical', | ||
| 80 | + 'is_filter', | ||
| 81 | + 'display', | ||
| 82 | + 'is_menu', | ||
| 83 | + 'use_in_name', | ||
| 84 | + ], | ||
| 85 | + 'boolean', | ||
| 86 | + ], | ||
| 87 | + [ | ||
| 88 | + [ | ||
| 89 | + 'level', | ||
| 90 | + 'sort', | ||
| 91 | + ], | ||
| 92 | + 'integer', | ||
| 93 | + ], | ||
| 94 | + [ | ||
| 95 | + [ | ||
| 96 | + 'alias', | ||
| 97 | + 'module', | ||
| 98 | + ], | ||
| 99 | + 'string', | ||
| 100 | + 'max' => 50, | ||
| 101 | + ], | ||
| 102 | + [ | ||
| 103 | + [ 'name' ], | ||
| 104 | + 'string', | ||
| 105 | + 'max' => 255, | ||
| 106 | + ], | ||
| 107 | + [ | ||
| 108 | + [ 'categories' ], | ||
| 109 | + 'safe', | ||
| 110 | + ], | ||
| 111 | + [ | ||
| 112 | + [ 'use_in_name' ], | ||
| 113 | + 'default', | ||
| 114 | + 'value' => false, | ||
| 115 | + ], | ||
| 116 | + ]; | ||
| 117 | + } | ||
| 118 | + | ||
| 119 | + /** | ||
| 120 | + * @inheritdoc | ||
| 121 | + */ | ||
| 122 | + public function attributeLabels() | ||
| 123 | + { | ||
| 124 | + return [ | ||
| 125 | + 'tax_group_id' => 'Tax Group ID', | ||
| 126 | + 'alias' => 'Alias', | ||
| 127 | + 'name' => 'Name', | ||
| 128 | + 'description' => 'Description', | ||
| 129 | + 'module' => 'Module', | ||
| 130 | + 'hierarchical' => 'Hierarchical', | ||
| 131 | + // 'settings' => 'Settings', | ||
| 132 | + 'is_filter' => 'Use in filter', | ||
| 133 | + 'sort' => 'Sort', | ||
| 134 | + 'display' => 'Display', | ||
| 135 | + 'is_menu' => 'ะัะพะฑัะฐะถะฐัั ะฒ ะผะตะฝั', | ||
| 136 | + 'use_in_name' => 'ะัะฟะพะปัะทะพะฒะฐัั ะฒ ะฝะฐะทะฒะฐะฝะธะธ', | ||
| 137 | + ]; | ||
| 138 | + } | ||
| 139 | + | ||
| 140 | + /** | ||
| 141 | + * @return \yii\db\ActiveQuery | ||
| 142 | + */ | ||
| 143 | + public function getTaxGroupToGroups() | ||
| 144 | + { | ||
| 145 | + return $this->hasMany(TaxGroupToGroup::className(), [ 'tax_group1_id' => 'tax_group_id' ]) | ||
| 146 | + ->inverseOf('taxGroup1'); | ||
| 147 | + } | ||
| 148 | + | ||
| 149 | + public function getCategories() | ||
| 150 | + { | ||
| 151 | + return $this->hasMany(Category::className(), [ 'category_id' => 'category_id' ]) | ||
| 152 | + ->viaTable('tax_group_to_category', [ 'tax_group_id' => 'tax_group_id' ]); | ||
| 153 | + } | ||
| 154 | + | ||
| 155 | + /** | ||
| 156 | + * @return ActiveQuery | ||
| 157 | + */ | ||
| 158 | + public function getCategory() | ||
| 159 | + { | ||
| 160 | + return $this->hasOne(Category::className(), [ 'category_id' => 'category_id' ]) | ||
| 161 | + ->viaTable('tax_group_to_category', [ 'tax_group_id' => 'tax_group_id' ]); | ||
| 162 | + } | ||
| 163 | + | ||
| 164 | + public function setCategories($values) | ||
| 165 | + { | ||
| 166 | + $this->categories = $values; | ||
| 167 | + } | ||
| 168 | + | ||
| 169 | + public function afterSave($insert, $changedAttributes) | ||
| 170 | + { | ||
| 171 | + | ||
| 172 | + $this->unlinkAll('categories', true); | ||
| 173 | + $categories = Category::findAll($this->categories); | ||
| 174 | + foreach ($categories as $category) { | ||
| 175 | + $this->link('categories', $category); | ||
| 176 | + } | ||
| 177 | + | ||
| 178 | + } | ||
| 179 | + | ||
| 180 | + /** | ||
| 181 | + * @return \yii\db\ActiveQuery | ||
| 182 | + */ | ||
| 183 | + public function getOptions() | ||
| 184 | + { | ||
| 185 | + return $this->getTaxOptions(); | ||
| 186 | + } | ||
| 187 | + public function getTaxOptions() | ||
| 188 | + { | ||
| 189 | + return $this->hasMany(TaxOption::className(), [ 'tax_group_id' => 'tax_group_id' ]) | ||
| 190 | + ->inverseOf('taxGroup'); | ||
| 191 | + } | ||
| 192 | + | ||
| 193 | + /** | ||
| 194 | + * @return \yii\db\ActiveQuery | ||
| 195 | + */ | ||
| 196 | + public function getTaxOptionToGroups() | ||
| 197 | + { | ||
| 198 | + return $this->hasMany(TaxOptionToGroup::className(), [ 'tax_group_id' => 'tax_group_id' ]) | ||
| 199 | + ->inverseOf('taxGroup'); | ||
| 200 | + } | ||
| 201 | + | ||
| 202 | + public function getValueModelName($full_path = true) | ||
| 203 | + { | ||
| 204 | + $valueClass = 'TaxValue' . ucfirst($this->module); | ||
| 205 | + $fullClass = '\common\modules\rubrication\models\\' . $valueClass; | ||
| 206 | + return class_exists($fullClass) ? $full_path ? $fullClass : $valueClass : false; | ||
| 119 | } | 207 | } |
| 120 | - | ||
| 121 | - | ||
| 122 | - } | ||
| 123 | - | ||
| 124 | - /** | ||
| 125 | - * @return \yii\db\ActiveQuery | ||
| 126 | - */ | ||
| 127 | - public function getOptions() { | ||
| 128 | - return $this->getTaxOptions(); | ||
| 129 | - } | ||
| 130 | - public function getTaxOptions() | ||
| 131 | - { | ||
| 132 | - return $this->hasMany(TaxOption::className(), ['tax_group_id' => 'tax_group_id'])->inverseOf('taxGroup'); | ||
| 133 | - } | ||
| 134 | - | ||
| 135 | - /** | ||
| 136 | - * @return \yii\db\ActiveQuery | ||
| 137 | - */ | ||
| 138 | - public function getTaxOptionToGroups() | ||
| 139 | - { | ||
| 140 | - return $this->hasMany(TaxOptionToGroup::className(), ['tax_group_id' => 'tax_group_id'])->inverseOf('taxGroup'); | ||
| 141 | - } | ||
| 142 | - | ||
| 143 | - public function getValueModelName($full_path = true) { | ||
| 144 | - $valueClass = 'TaxValue'. ucfirst($this->module); | ||
| 145 | - $fullClass = '\common\modules\rubrication\models\\'. $valueClass; | ||
| 146 | - return class_exists($fullClass) ? $full_path ? $fullClass : $valueClass : FALSE; | ||
| 147 | } | 208 | } |
| 148 | -} |
console/config/main.php
| @@ -13,7 +13,7 @@ return [ | @@ -13,7 +13,7 @@ return [ | ||
| 13 | 'controllerNamespace' => 'console\controllers', | 13 | 'controllerNamespace' => 'console\controllers', |
| 14 | 'components' => [ | 14 | 'components' => [ |
| 15 | 'urlManager' => [ | 15 | 'urlManager' => [ |
| 16 | - 'baseUrl' => 'http://www.linija-svitla.ua', | 16 | + 'baseUrl' => 'https://www.linija-svitla.ua', |
| 17 | 'enablePrettyUrl' => true, | 17 | 'enablePrettyUrl' => true, |
| 18 | 'showScriptName' => false, | 18 | 'showScriptName' => false, |
| 19 | 19 |
console/controllers/SiteMapController.php
| 1 | <?php | 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\Console; | ||
| 17 | -use yii\helpers\Url; | ||
| 18 | -use yii\console\Controller; | ||
| 19 | -use yii\web\NotFoundHttpException; | ||
| 20 | -use yii\filters\VerbFilter; | ||
| 21 | -use developeruz\db_rbac\behaviors\AccessBehavior; | ||
| 22 | -/** | ||
| 23 | - * PageController implements the CRUD actions for Page model. | ||
| 24 | - */ | ||
| 25 | -class SiteMapController extends Controller | ||
| 26 | -{ | ||
| 27 | - | ||
| 28 | - private $urlList = ['http://www.linija-svitla.ua/']; | ||
| 29 | - private $count = 1; | ||
| 30 | - | ||
| 31 | - | ||
| 32 | - | ||
| 33 | - public function checkFilter($category, $filter){ | ||
| 34 | - $productModel = new ProductFrontendSearch(); | ||
| 35 | - $productProvider = $productModel->search($category, $filter); | ||
| 36 | - if(!empty($productProvider->models)){ | ||
| 37 | - return true; | ||
| 38 | - } else { | ||
| 39 | - return false; | ||
| 40 | - } | ||
| 41 | - } | ||
| 42 | - | ||
| 43 | - | ||
| 44 | - | ||
| 45 | - public function getAddStatic(){ | ||
| 46 | - return [ | ||
| 47 | - 'http://www.linija-svitla.ua', | ||
| 48 | - 'http://www.linija-svitla.ua/catalog' | ||
| 49 | - ]; | ||
| 50 | - } | ||
| 51 | - | ||
| 52 | - | ||
| 53 | - public function getProducts() { | ||
| 54 | - return Product::find()->all(); | ||
| 55 | - | ||
| 56 | - } | ||
| 57 | - | ||
| 58 | - | ||
| 59 | - public function getSeoLinks() { | ||
| 60 | - return Seo::find()->where(['meta' => ''])->all(); | ||
| 61 | - | ||
| 62 | - } | ||
| 63 | - | ||
| 64 | - public function getStaticPages(){ | ||
| 65 | - return Page::find()->all(); | ||
| 66 | - } | ||
| 67 | - | ||
| 68 | - | ||
| 69 | - public function getCategories(){ | ||
| 70 | - return Category::find()->all(); | ||
| 71 | - } | ||
| 72 | - | ||
| 73 | - | ||
| 74 | - public function getArticles(){ | ||
| 75 | - return Articles::find()->all(); | ||
| 76 | - } | ||
| 77 | - | ||
| 78 | - public function getBrands($category){ | ||
| 79 | - | ||
| 80 | - return $category->brands; | ||
| 81 | - } | ||
| 82 | - | 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 common\modules\rubrication\models\TaxOption; | ||
| 12 | + use frontend\models\ProductFrontendSearch; | ||
| 13 | + use Yii; | ||
| 14 | + use common\models\Page; | ||
| 15 | + use common\models\PageSearch; | ||
| 16 | + use yii\helpers\ArrayHelper; | ||
| 17 | + use yii\helpers\Console; | ||
| 18 | + use yii\helpers\Url; | ||
| 19 | + use yii\console\Controller; | ||
| 20 | + use yii\web\NotFoundHttpException; | ||
| 21 | + use yii\filters\VerbFilter; | ||
| 22 | + use developeruz\db_rbac\behaviors\AccessBehavior; | ||
| 23 | + | ||
| 83 | /** | 24 | /** |
| 84 | - * @param $category Category; | ||
| 85 | - * @return mixed | 25 | + * PageController implements the CRUD actions for Page model. |
| 86 | */ | 26 | */ |
| 87 | - | ||
| 88 | - public function getFilters($category){ | ||
| 89 | - | ||
| 90 | - return $category->getActiveFilters(); | ||
| 91 | - | ||
| 92 | - } | ||
| 93 | - | ||
| 94 | - | ||
| 95 | - public function checkUrl($url){ | ||
| 96 | - if(!in_array($url, $this->urlList)){ | ||
| 97 | - $this->urlList[] = $url; | ||
| 98 | - return true; | ||
| 99 | - } else { | ||
| 100 | - return false; | 27 | + class SiteMapController extends Controller |
| 28 | + { | ||
| 29 | + | ||
| 30 | + private $urlList = [ 'http://www.linija-svitla.ua/' ]; | ||
| 31 | + private $count = 1; | ||
| 32 | + | ||
| 33 | + public function checkFilter($category, $filter) | ||
| 34 | + { | ||
| 35 | + $productModel = new ProductFrontendSearch(); | ||
| 36 | + $productProvider = $productModel->search($category, $filter); | ||
| 37 | + if (!empty($productProvider->models)) { | ||
| 38 | + return true; | ||
| 39 | + } else { | ||
| 40 | + return false; | ||
| 41 | + } | ||
| 101 | } | 42 | } |
| 102 | - } | ||
| 103 | - | ||
| 104 | - | ||
| 105 | - public function createRow( $url, $priority, &$content ){ | ||
| 106 | -// if($this->checkUrl($url)){ | ||
| 107 | - $this->stdout( '# ' . $this->count++ . "\n", Console::FG_GREEN); | ||
| 108 | - $content .= '<url>' . | ||
| 109 | - '<loc>' . $url . '</loc>' . | ||
| 110 | - '<lastmod>' . date('Y-m-d') . '</lastmod>' . | ||
| 111 | - '<changefreq>Weekly</changefreq>' . | ||
| 112 | - '<priority>' . $priority .'</priority>' . | ||
| 113 | - '</url>'; | ||
| 114 | -// } | ||
| 115 | - } | ||
| 116 | - | ||
| 117 | - | ||
| 118 | - public function actionProcess() { | ||
| 119 | - | ||
| 120 | - $config = ArrayHelper::merge( | ||
| 121 | - require(__DIR__ . '/../../frontend/config/main.php'), | ||
| 122 | - require(__DIR__ . '/../../common/config/main.php') | ||
| 123 | - | ||
| 124 | - ); | ||
| 125 | - | ||
| 126 | - Yii::$app->urlManager->addRules($config['components']['urlManager']['rules']); | ||
| 127 | - | ||
| 128 | - $this->stdout('Start!' . "\n", Console::FG_RED); | ||
| 129 | - | ||
| 130 | - $dirName = Yii::getAlias('@frontend').'/web'; | ||
| 131 | - | ||
| 132 | - $filename = 'sitemap.xml'; | ||
| 133 | - | ||
| 134 | - setlocale(LC_ALL, 'ru_RU.CP1251'); | ||
| 135 | - $handle = fopen($dirName .'/'. $filename, "w"); | ||
| 136 | - | ||
| 137 | - $content = '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'; | ||
| 138 | 43 | ||
| 139 | - $this->stdout('Add static' . "\n", Console::FG_BLUE); | ||
| 140 | - | ||
| 141 | - foreach ($this->getAddStatic() as $page) { | ||
| 142 | - $this->createRow($page , 1,$content); | 44 | + /** |
| 45 | + * @return array | ||
| 46 | + */ | ||
| 47 | + public function getAddStatic() | ||
| 48 | + { | ||
| 49 | + return [ | ||
| 50 | + 'https://www.linija-svitla.ua', | ||
| 51 | + 'https://www.linija-svitla.ua/catalog', | ||
| 52 | + ]; | ||
| 143 | } | 53 | } |
| 144 | - $this->stdout('Add static pages' . "\n", Console::FG_BLUE); | ||
| 145 | - | ||
| 146 | - foreach ($this->getStaticPages() as $page) { | ||
| 147 | - $url = Url::to(['text/main','translit' => $page->translit]); | ||
| 148 | - | ||
| 149 | - $this->createRow($url , 1,$content); | 54 | + |
| 55 | + /** | ||
| 56 | + * @return array|\yii\db\ActiveRecord[] | ||
| 57 | + */ | ||
| 58 | + public function getProducts() | ||
| 59 | + { | ||
| 60 | + return Product::find() | ||
| 61 | + ->all(); | ||
| 62 | + | ||
| 150 | } | 63 | } |
| 151 | - $this->stdout('Add categories' . "\n", Console::FG_BLUE); | ||
| 152 | - | ||
| 153 | - foreach ($this->getCategories() as $category) { | ||
| 154 | - | ||
| 155 | - $url = Url::to(['catalog/category', 'category' => $category]); | ||
| 156 | - $this->createRow($url , 1,$content); | 64 | + |
| 65 | + /** | ||
| 66 | + * @return array|\yii\db\ActiveRecord[] | ||
| 67 | + */ | ||
| 68 | + public function getSeoLinks() | ||
| 69 | + { | ||
| 70 | + return Seo::find() | ||
| 71 | + ->where( | ||
| 72 | + [ | ||
| 73 | + 'not like', | ||
| 74 | + 'meta', | ||
| 75 | + '%noindex%', | ||
| 76 | + ] | ||
| 77 | + ) | ||
| 78 | + ->all(); | ||
| 79 | + | ||
| 157 | } | 80 | } |
| 158 | - | ||
| 159 | - $this->stdout('Add products' . "\n", Console::FG_BLUE); | ||
| 160 | - | ||
| 161 | - foreach ($this->getProducts() as $product) { | ||
| 162 | - | ||
| 163 | - $url = Url::to(['catalog/product', 'product' => $product]); | ||
| 164 | - $this->createRow($url , 0.9, $content); | 81 | + |
| 82 | + /** | ||
| 83 | + * @return array|\yii\db\ActiveRecord[] | ||
| 84 | + */ | ||
| 85 | + public function getStaticPages() | ||
| 86 | + { | ||
| 87 | + return Page::find() | ||
| 88 | + ->all(); | ||
| 165 | } | 89 | } |
| 166 | - | ||
| 167 | - $this->stdout('Add articles' . "\n", Console::FG_BLUE); | ||
| 168 | - | ||
| 169 | - foreach ($this->getArticles() as $article) { | ||
| 170 | - | ||
| 171 | - $url = Url::to(['articles/show', 'translit' => $article->translit]); | ||
| 172 | - $this->createRow($url , 0.8,$content); | ||
| 173 | - | 90 | + |
| 91 | + /** | ||
| 92 | + * @return array|\common\modules\product\models\Category[]|\yii\db\ActiveRecord[] | ||
| 93 | + */ | ||
| 94 | + public function getCategories() | ||
| 95 | + { | ||
| 96 | + return Category::find() | ||
| 97 | + ->all(); | ||
| 174 | } | 98 | } |
| 175 | - | ||
| 176 | - $this->stdout('Add brands' . "\n", Console::FG_BLUE); | ||
| 177 | - | ||
| 178 | - foreach($this->getCategories() as $category){ | ||
| 179 | - foreach ($this->getBrands($category) as $brand) { | ||
| 180 | - if($this->checkFilter($category, ['brands' => [$brand->brand_id]])){ | ||
| 181 | - $url = Url::to(['catalog/category', 'category' => $category, 'filters' => ['brands' => [$brand->alias]]]) ; | ||
| 182 | - $this->createRow($url , 0.8, $content); | ||
| 183 | - } | 99 | + |
| 100 | + /** | ||
| 101 | + * @return array|\yii\db\ActiveRecord[] | ||
| 102 | + */ | ||
| 103 | + public function getArticles() | ||
| 104 | + { | ||
| 105 | + return Articles::find() | ||
| 106 | + ->all(); | ||
| 107 | + } | ||
| 108 | + | ||
| 109 | + /** | ||
| 110 | + * @param $category | ||
| 111 | + * | ||
| 112 | + * @return mixed | ||
| 113 | + */ | ||
| 114 | + public function getBrands($category) | ||
| 115 | + { | ||
| 116 | + | ||
| 117 | + return $category->brands; | ||
| 118 | + } | ||
| 119 | + | ||
| 120 | + /** | ||
| 121 | + * @return array|\yii\db\ActiveRecord[] | ||
| 122 | + */ | ||
| 123 | + public function getOptions() | ||
| 124 | + { | ||
| 125 | + | ||
| 126 | + return TaxOption::find() | ||
| 127 | + ->innerJoinWith( | ||
| 128 | + [ | ||
| 129 | + 'taxGroup.category', | ||
| 130 | + ] | ||
| 131 | + ) | ||
| 132 | + ->all(); | ||
| 133 | + | ||
| 134 | + } | ||
| 135 | + | ||
| 136 | + public function checkUrl($url) | ||
| 137 | + { | ||
| 138 | + if (!in_array($url, $this->urlList)) { | ||
| 139 | + $this->urlList[] = $url; | ||
| 140 | + return true; | ||
| 141 | + } else { | ||
| 142 | + return false; | ||
| 184 | } | 143 | } |
| 185 | } | 144 | } |
| 186 | - | ||
| 187 | - $this->stdout('Add filters' . "\n", Console::FG_BLUE); | ||
| 188 | - | ||
| 189 | - foreach($this->getCategories() as $category){ | ||
| 190 | - foreach ($this->getFilters($category) as $filter) { | ||
| 191 | - if($this->checkFilter($category, [$filter['group_alias'] => [$filter['option_alias']]])){ | ||
| 192 | - $url = Url::to(['catalog/category', 'category' => $category, 'filters' => [$filter['group_alias'] => [$filter['option_alias']]] ]); | ||
| 193 | - $this->createRow($url , 0.8, $content); | 145 | + |
| 146 | + public function createRow($url, $priority, &$content) | ||
| 147 | + { | ||
| 148 | + // if($this->checkUrl($url)){ | ||
| 149 | + $this->stdout('# ' . $this->count++ . ' ' . $url . "\n", Console::FG_GREEN); | ||
| 150 | + $content .= '<url>' . '<loc>' . $url . '</loc>' . '<lastmod>' . date( | ||
| 151 | + 'Y-m-d' | ||
| 152 | + ) . '</lastmod>' . '<changefreq>Weekly</changefreq>' . '<priority>' . $priority . '</priority>' . '</url>'; | ||
| 153 | + // } | ||
| 154 | + } | ||
| 155 | + | ||
| 156 | + public function actionProcess() | ||
| 157 | + { | ||
| 158 | + | ||
| 159 | + $config = ArrayHelper::merge( | ||
| 160 | + require( __DIR__ . '/../../frontend/config/main.php' ), | ||
| 161 | + require( __DIR__ . '/../../common/config/main.php' ) | ||
| 162 | + | ||
| 163 | + ); | ||
| 164 | + | ||
| 165 | + Yii::$app->urlManager->addRules($config[ 'components' ][ 'urlManager' ][ 'rules' ]); | ||
| 166 | + | ||
| 167 | + $this->stdout('Start!' . "\n", Console::FG_RED); | ||
| 168 | + | ||
| 169 | + $dirName = Yii::getAlias('@frontend') . '/web'; | ||
| 170 | + | ||
| 171 | + $filename = 'sitemap.xml'; | ||
| 172 | + | ||
| 173 | + setlocale(LC_ALL, 'ru_RU.CP1251'); | ||
| 174 | + $handle = fopen($dirName . '/' . $filename, "w"); | ||
| 175 | + | ||
| 176 | + $content = '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'; | ||
| 177 | + | ||
| 178 | + $this->stdout('Add static' . "\n", Console::FG_BLUE); | ||
| 179 | + | ||
| 180 | + foreach ($this->getAddStatic() as $page) { | ||
| 181 | + $this->createRow($page, 1, $content); | ||
| 182 | + } | ||
| 183 | + $this->stdout('Add static pages' . "\n", Console::FG_BLUE); | ||
| 184 | + | ||
| 185 | + foreach ($this->getStaticPages() as $page) { | ||
| 186 | + $url = Url::to( | ||
| 187 | + [ | ||
| 188 | + 'text/main', | ||
| 189 | + 'translit' => $page->translit, | ||
| 190 | + ], | ||
| 191 | + true | ||
| 192 | + ); | ||
| 193 | + | ||
| 194 | + $this->createRow($url, 1, $content); | ||
| 195 | + } | ||
| 196 | + $this->stdout('Add categories' . "\n", Console::FG_BLUE); | ||
| 197 | + | ||
| 198 | + foreach ($this->getCategories() as $category) { | ||
| 199 | + | ||
| 200 | + $url = Url::to( | ||
| 201 | + [ | ||
| 202 | + 'catalog/category', | ||
| 203 | + 'category' => $category, | ||
| 204 | + ], | ||
| 205 | + true | ||
| 206 | + ); | ||
| 207 | + $this->createRow($url, 1, $content); | ||
| 208 | + } | ||
| 209 | + | ||
| 210 | + $this->stdout('Add products' . "\n", Console::FG_BLUE); | ||
| 211 | + | ||
| 212 | + foreach ($this->getProducts() as $product) { | ||
| 213 | + | ||
| 214 | + $url = Url::to( | ||
| 215 | + [ | ||
| 216 | + 'catalog/product', | ||
| 217 | + 'product' => $product, | ||
| 218 | + ], | ||
| 219 | + true | ||
| 220 | + ); | ||
| 221 | + $this->createRow($url, 0.9, $content); | ||
| 222 | + } | ||
| 223 | + | ||
| 224 | + $this->stdout('Add articles' . "\n", Console::FG_BLUE); | ||
| 225 | + | ||
| 226 | + foreach ($this->getArticles() as $article) { | ||
| 227 | + | ||
| 228 | + $url = Url::to( | ||
| 229 | + [ | ||
| 230 | + 'articles/show', | ||
| 231 | + 'translit' => $article->translit, | ||
| 232 | + ], | ||
| 233 | + true | ||
| 234 | + ); | ||
| 235 | + $this->createRow($url, 0.8, $content); | ||
| 236 | + | ||
| 237 | + } | ||
| 238 | + | ||
| 239 | + $this->stdout('Add brands' . "\n", Console::FG_BLUE); | ||
| 240 | + | ||
| 241 | + foreach ($this->getCategories() as $category) { | ||
| 242 | + foreach ($this->getBrands($category) as $brand) { | ||
| 243 | + if ($this->checkFilter($category, [ 'brands' => [ $brand->brand_id ] ])) { | ||
| 244 | + $url = Url::to( | ||
| 245 | + [ | ||
| 246 | + 'catalog/category', | ||
| 247 | + 'category' => $category, | ||
| 248 | + 'filters' => [ 'brands' => [ $brand->alias ] ], | ||
| 249 | + ], | ||
| 250 | + true | ||
| 251 | + ); | ||
| 252 | + $this->createRow($url, 0.8, $content); | ||
| 253 | + } | ||
| 194 | } | 254 | } |
| 195 | - | ||
| 196 | } | 255 | } |
| 256 | + | ||
| 257 | + $this->stdout('Add filters' . "\n", Console::FG_BLUE); | ||
| 258 | + | ||
| 259 | + foreach ($this->getOptions() as $option) { | ||
| 260 | + $url = Url::to( | ||
| 261 | + [ | ||
| 262 | + 'catalog/category', | ||
| 263 | + 'category' => $option->taxGroup->category, | ||
| 264 | + 'filters' => [ $option->taxGroup->alias => [ $option->alias ] ], | ||
| 265 | + ], | ||
| 266 | + true | ||
| 267 | + ); | ||
| 268 | + $this->createRow($url, 0.8, $content); | ||
| 269 | + } | ||
| 270 | + | ||
| 271 | + $this->stdout('Add seo links' . "\n", Console::FG_BLUE); | ||
| 272 | + | ||
| 273 | + foreach ($this->getSeoLinks() as $link) { | ||
| 274 | + $url = Yii::$app->urlManager->baseUrl . $link->url; | ||
| 275 | + $this->createRow($url, 0.7, $content); | ||
| 276 | + | ||
| 277 | + } | ||
| 278 | + | ||
| 279 | + $content .= '</urlset>'; | ||
| 280 | + | ||
| 281 | + fwrite($handle, $content); | ||
| 282 | + fclose($handle); | ||
| 283 | + $this->stdout('File name: ' . $dirName . '/' . $filename . "\n", Console::FG_CYAN); | ||
| 284 | + | ||
| 197 | } | 285 | } |
| 198 | - | ||
| 199 | - $this->stdout('Add seo links' . "\n", Console::FG_BLUE); | ||
| 200 | - | ||
| 201 | - foreach($this->getSeoLinks() as $link){ | ||
| 202 | - $url = Yii::$app->urlManager->baseUrl.$link->url; | ||
| 203 | - $this->createRow($url , 0.7, $content); | ||
| 204 | - | ||
| 205 | - } | ||
| 206 | - | ||
| 207 | - | ||
| 208 | - | ||
| 209 | -// foreach($this->getCategories() as $category){ | ||
| 210 | -// foreach ($this->getFilters($category) as $filter1) { | ||
| 211 | -// foreach ($this->getFilters($category) as $filter2) { | ||
| 212 | -// if($this->checkFilter($category, [$filter1['group_alias'] => [$filter1['option_alias']],$filter2['group_alias'] => [$filter2['option_alias']]] )){ | ||
| 213 | -// $url = Url::to(['catalog/category', 'category' => $category, 'filters' => [$filter1['group_alias'] => [$filter1['option_alias']],$filter2['group_alias'] => [$filter2['option_alias']]] ]); | ||
| 214 | -// $this->createRow($url , 0.7, $content); | ||
| 215 | -// } | ||
| 216 | -// | ||
| 217 | -// } | ||
| 218 | -// | ||
| 219 | -// foreach ($this->getBrands($category) as $brand) { | ||
| 220 | -// if($this->checkFilter($category, ['brands' => [$brand->brand_id], $filter1['group_alias'] => [$filter1['option_alias']]] )){ | ||
| 221 | -// $url = Url::to(['catalog/category', 'category' => $category, 'filters' => ['brands' => [$brand->alias],$filter1['group_alias'] => [$filter1['option_alias']]]]); | ||
| 222 | -// $this->createRow($url , 0.7,$content); | ||
| 223 | -// } | ||
| 224 | -// | ||
| 225 | -// } | ||
| 226 | -// } | ||
| 227 | -// } | ||
| 228 | - | ||
| 229 | - | ||
| 230 | - | ||
| 231 | - $content .= '</urlset>'; | ||
| 232 | - | ||
| 233 | - fwrite($handle, $content); | ||
| 234 | - fclose($handle); | ||
| 235 | - $this->stdout('File name: ' . $dirName .'/'. $filename . "\n", Console::FG_CYAN); | ||
| 236 | 286 | ||
| 237 | } | 287 | } |
| 238 | - | ||
| 239 | -} |