Commit 6651017672469b3f2a03d3ab19bf0c59d67ffd5b
1 parent
5d972c58
-Sitemap excluded empty filters
Showing
2 changed files
with
298 additions
and
230 deletions
Show diff stats
common/modules/rubrication/models/TaxOption.php
1 | 1 | <?php |
2 | - | |
3 | -namespace common\modules\rubrication\models; | |
4 | - | |
5 | -use Yii; | |
6 | -use common\components\artboxtree\ArtboxTreeBehavior; | |
7 | -use yii\db\ActiveRecord; | |
8 | - | |
9 | -/** | |
10 | - * This is the model class for table "{{%tax_option}}". | |
11 | - * | |
12 | - * @property string $tax_option_id | |
13 | - * @property integer $tax_group_id | |
14 | - * @property integer $parent_id | |
15 | - * @property integer $tree | |
16 | - * @property string $path_int | |
17 | - * @property integer $depth | |
18 | - * @property string $alias | |
19 | - * @property integer $sort | |
20 | - * @property integer $default_value | |
21 | - * @property integer $name | |
22 | - * @property array $image | |
23 | - * @property string $synonym | |
24 | - * | |
25 | - * @property TaxEntityRelation[] $taxEntityRelations | |
26 | - * @property TaxGroup $taxGroup | |
27 | - * @property TaxOption $parent | |
28 | - * @property TaxOption[] $taxOptions | |
29 | - * @property TaxOptionToGroup[] $taxOptionToGroups | |
30 | - * @property TaxOptionToOption[] $taxOptionToOptions | |
31 | - * @property TaxOptionToOption[] $taxOptionToOptions0 | |
32 | - * @property TaxValueFloat[] $taxValueFloats | |
33 | - * @property TaxValueInt[] $taxValueInts | |
34 | - * @property TaxValueString[] $taxValueStrings | |
35 | - * @property TaxValueText[] $taxValueTexts | |
36 | - */ | |
37 | -class TaxOption extends \yii\db\ActiveRecord | |
38 | -{ | |
39 | - public $_items_count; | |
40 | - | |
41 | - | |
2 | + | |
3 | + namespace common\modules\rubrication\models; | |
4 | + | |
5 | + use common\modules\product\models\Product; | |
6 | + use Yii; | |
7 | + use common\components\artboxtree\ArtboxTreeBehavior; | |
8 | + use yii\db\ActiveQuery; | |
9 | + use yii\db\ActiveRecord; | |
10 | + | |
42 | 11 | /** |
43 | - * @inheritdoc | |
12 | + * This is the model class for table "{{%tax_option}}". | |
13 | + * | |
14 | + * @property string $tax_option_id | |
15 | + * @property integer $tax_group_id | |
16 | + * @property integer $parent_id | |
17 | + * @property integer $tree | |
18 | + * @property string $path_int | |
19 | + * @property integer $depth | |
20 | + * @property string $alias | |
21 | + * @property integer $sort | |
22 | + * @property integer $default_value | |
23 | + * @property integer $name | |
24 | + * @property array $image | |
25 | + * @property string $synonym | |
26 | + * @property TaxEntityRelation[] $taxEntityRelations | |
27 | + * @property TaxGroup $taxGroup | |
28 | + * @property TaxOption $parent | |
29 | + * @property TaxOption[] $taxOptions | |
30 | + * @property TaxOptionToGroup[] $taxOptionToGroups | |
31 | + * @property TaxOptionToOption[] $taxOptionToOptions | |
32 | + * @property TaxOptionToOption[] $taxOptionToOptions0 | |
33 | + * @property TaxValueFloat[] $taxValueFloats | |
34 | + * @property TaxValueInt[] $taxValueInts | |
35 | + * @property TaxValueString[] $taxValueStrings | |
36 | + * @property TaxValueText[] $taxValueTexts | |
44 | 37 | */ |
45 | - public function behaviors() | |
38 | + class TaxOption extends \yii\db\ActiveRecord | |
46 | 39 | { |
47 | - return [ | |
48 | - 'artboxtree' => [ | |
49 | - 'class' => ArtboxTreeBehavior::className(), | |
50 | - 'keyNameGroup' => 'tax_group_id', | |
51 | - ], | |
52 | - 'slug' => [ | |
53 | - 'class' => 'common\behaviors\Slug', | |
54 | - 'in_attribute' => 'name', | |
55 | - 'out_attribute' => 'alias', | |
56 | - 'translit' => true | |
57 | - ], | |
58 | - | |
59 | - ]; | |
60 | - } | |
61 | - | |
40 | + public $_items_count; | |
41 | + | |
62 | 42 | /** |
63 | - * @inheritdoc | |
64 | - */ | |
65 | - public static function tableName() | |
66 | - { | |
67 | - return '{{%tax_option}}'; | |
68 | - } | |
69 | - | |
70 | - /** | |
71 | - * @inheritdoc | |
72 | - */ | |
73 | - public function rules() | |
74 | - { | |
75 | - return [ | |
76 | - [['tax_group_id','name'], 'required'], | |
77 | - [['tax_group_id', 'parent_id', 'sort', 'default_value'], 'integer'], | |
78 | - [['image','alias', 'value', 'synonym'], 'string', 'max' => 255], | |
79 | - [['tax_group_id'], 'exist', 'skipOnError' => true, 'targetClass' => TaxGroup::className(), 'targetAttribute' => ['tax_group_id' => 'tax_group_id']], | |
80 | - ]; | |
81 | - } | |
82 | - | |
83 | - /** | |
84 | - * @inheritdoc | |
85 | - */ | |
86 | - public function attributeLabels() | |
87 | - { | |
88 | - return [ | |
89 | - 'tax_option_id' => Yii::t('app', 'Tax Option ID'), | |
90 | - 'tax_group_id' => Yii::t('app', 'Tax Group ID'), | |
91 | - 'parent_id' => Yii::t('app', 'Parent ID'), | |
92 | - 'alias' => Yii::t('app', 'Alias'), | |
93 | - 'sort' => Yii::t('app', 'Sort'), | |
94 | - 'default_value' => Yii::t('app', 'Default Value'), | |
95 | - 'image' => Yii::t('product', 'Image'), | |
96 | - 'synonym' => Yii::t('product', 'ะกะธะฝะพะฝะธะผ'), | |
97 | - ]; | |
98 | - } | |
99 | - | |
100 | - public static function find() { | |
101 | - return new TaxOptionQuery(get_called_class()); | |
102 | - } | |
103 | - | |
104 | - /** | |
105 | - * @return \yii\db\ActiveQuery | |
106 | - */ | |
107 | - public function getTaxEntityRelations() | |
108 | - { | |
109 | - return $this->hasMany(TaxEntityRelation::className(), ['tax_option_id' => 'tax_option_id'])->inverseOf('taxOption'); | |
110 | - } | |
111 | - | |
112 | - | |
113 | - /** | |
114 | - * @return \yii\db\ActiveQuery | |
115 | - */ | |
116 | - public function getGroup() | |
117 | - { | |
118 | - return $this->getTaxGroup(); | |
119 | - } | |
120 | - | |
121 | - /** | |
122 | - * @return \yii\db\ActiveQuery | |
123 | - */ | |
124 | - public function getTaxGroup() | |
125 | - { | |
126 | - return $this->hasOne(TaxGroup::className(), ['tax_group_id' => 'tax_group_id'])->inverseOf('taxOptions'); | |
127 | - } | |
128 | - | |
129 | - /** | |
130 | - * @return \yii\db\ActiveQuery | |
131 | - */ | |
132 | - public function getTaxOptions() | |
133 | - { | |
134 | - return $this->hasMany(TaxOption::className(), ['parent_id' => 'tax_option_id'])->inverseOf('parent'); | |
135 | - } | |
136 | - | |
137 | - /** | |
138 | - * @return \yii\db\ActiveQuery | |
139 | - */ | |
140 | - public function getTaxOptionToGroups() | |
141 | - { | |
142 | - return $this->hasMany(TaxOptionToGroup::className(), ['tax_option_id' => 'tax_option_id'])->inverseOf('taxOption'); | |
143 | - } | |
144 | - | |
145 | - /** | |
146 | - * @return \yii\db\ActiveQuery | |
147 | - */ | |
148 | - public function getTaxOptionToOptions() | |
149 | - { | |
150 | - return $this->hasMany(TaxOptionToOption::className(), ['tax_option1_id' => 'tax_option_id'])->inverseOf('taxOption1'); | |
151 | - } | |
152 | - | |
153 | - /** | |
154 | - * @return \yii\db\ActiveQuery | |
155 | - */ | |
156 | - public function getTaxOptionToOptions0() | |
157 | - { | |
158 | - return $this->hasMany(TaxOptionToOption::className(), ['tax_option2_id' => 'tax_option_id'])->inverseOf('taxOption2'); | |
159 | - } | |
160 | - | |
161 | - | |
162 | - public function getTaxValueString(){ | |
163 | - return $this->name; | |
164 | - } | |
165 | - | |
166 | - | |
167 | - /** | |
168 | - */ | |
169 | - public function getValue() | |
170 | - { | |
171 | - return $this->name; | |
172 | - } | |
173 | - public function setValue($value){ | |
174 | - return $this->name = $value; | |
175 | - } | |
176 | - /** | |
177 | - */ | |
178 | - public function getValueRenderFlash() | |
179 | - { | |
180 | - return $this->name; | |
181 | - } | |
182 | - | |
183 | - /** | |
184 | - */ | |
185 | - public function getValueRenderHTML() | |
186 | - { | |
187 | - return $this->name; | |
188 | - } | |
189 | - | |
190 | - | |
191 | - | |
192 | - /** | |
193 | - * @return \yii\db\ActiveQuery | |
194 | - */ | |
195 | - public function getValues() | |
196 | - { | |
197 | - if ($valueClass = $this->getValueModelName()) | |
198 | - return $this->hasMany($valueClass, ['tax_option_id' => 'tax_option_id'])->inverseOf('taxOption')->cascadeOnDelete(); | |
199 | - } | |
200 | - | |
201 | - public function beforeSave($insert) | |
202 | - { | |
203 | - if (parent::beforeSave($insert)) { | |
204 | - | |
205 | - if (empty($this->parent_id)) | |
206 | - $this->parent_id = 0; | |
207 | - | |
208 | - | |
209 | - | |
210 | - return true; | |
211 | - } | |
212 | - return false; | |
213 | - } | |
214 | - | |
215 | - public function getImageFile() { | |
216 | - return empty($this->image) ? null : Yii::getAlias('@imagesDir/tax_option/'. $this->image); | |
217 | - } | |
218 | - | |
219 | - public function getImageUrl() | |
220 | - { | |
221 | - return empty($this->image) ? null : Yii::getAlias('@imagesUrl/tax_option/' . $this->image); | |
43 | + * @inheritdoc | |
44 | + */ | |
45 | + public function behaviors() | |
46 | + { | |
47 | + return [ | |
48 | + 'artboxtree' => [ | |
49 | + 'class' => ArtboxTreeBehavior::className(), | |
50 | + 'keyNameGroup' => 'tax_group_id', | |
51 | + ], | |
52 | + 'slug' => [ | |
53 | + 'class' => 'common\behaviors\Slug', | |
54 | + 'in_attribute' => 'name', | |
55 | + 'out_attribute' => 'alias', | |
56 | + 'translit' => true, | |
57 | + ], | |
58 | + | |
59 | + ]; | |
60 | + } | |
61 | + | |
62 | + /** | |
63 | + * @inheritdoc | |
64 | + */ | |
65 | + public static function tableName() | |
66 | + { | |
67 | + return '{{%tax_option}}'; | |
68 | + } | |
69 | + | |
70 | + /** | |
71 | + * @inheritdoc | |
72 | + */ | |
73 | + public function rules() | |
74 | + { | |
75 | + return [ | |
76 | + [ | |
77 | + [ | |
78 | + 'tax_group_id', | |
79 | + 'name', | |
80 | + ], | |
81 | + 'required', | |
82 | + ], | |
83 | + [ | |
84 | + [ | |
85 | + 'tax_group_id', | |
86 | + 'parent_id', | |
87 | + 'sort', | |
88 | + 'default_value', | |
89 | + ], | |
90 | + 'integer', | |
91 | + ], | |
92 | + [ | |
93 | + [ | |
94 | + 'image', | |
95 | + 'alias', | |
96 | + 'value', | |
97 | + 'synonym', | |
98 | + ], | |
99 | + 'string', | |
100 | + 'max' => 255, | |
101 | + ], | |
102 | + [ | |
103 | + [ 'tax_group_id' ], | |
104 | + 'exist', | |
105 | + 'skipOnError' => true, | |
106 | + 'targetClass' => TaxGroup::className(), | |
107 | + 'targetAttribute' => [ 'tax_group_id' => 'tax_group_id' ], | |
108 | + ], | |
109 | + ]; | |
110 | + } | |
111 | + | |
112 | + /** | |
113 | + * @inheritdoc | |
114 | + */ | |
115 | + public function attributeLabels() | |
116 | + { | |
117 | + return [ | |
118 | + 'tax_option_id' => Yii::t('app', 'Tax Option ID'), | |
119 | + 'tax_group_id' => Yii::t('app', 'Tax Group ID'), | |
120 | + 'parent_id' => Yii::t('app', 'Parent ID'), | |
121 | + 'alias' => Yii::t('app', 'Alias'), | |
122 | + 'sort' => Yii::t('app', 'Sort'), | |
123 | + 'default_value' => Yii::t('app', 'Default Value'), | |
124 | + 'image' => Yii::t('product', 'Image'), | |
125 | + 'synonym' => Yii::t('product', 'ะกะธะฝะพะฝะธะผ'), | |
126 | + ]; | |
127 | + } | |
128 | + | |
129 | + public static function find() | |
130 | + { | |
131 | + return new TaxOptionQuery(get_called_class()); | |
132 | + } | |
133 | + | |
134 | + /** | |
135 | + * @return \yii\db\ActiveQuery | |
136 | + */ | |
137 | + public function getTaxEntityRelations() | |
138 | + { | |
139 | + return $this->hasMany(TaxEntityRelation::className(), [ 'tax_option_id' => 'tax_option_id' ]) | |
140 | + ->inverseOf('taxOption'); | |
141 | + } | |
142 | + | |
143 | + /** | |
144 | + * @return \yii\db\ActiveQuery | |
145 | + */ | |
146 | + public function getGroup() | |
147 | + { | |
148 | + return $this->getTaxGroup(); | |
149 | + } | |
150 | + | |
151 | + /** | |
152 | + * @return \yii\db\ActiveQuery | |
153 | + */ | |
154 | + public function getTaxGroup() | |
155 | + { | |
156 | + return $this->hasOne(TaxGroup::className(), [ 'tax_group_id' => 'tax_group_id' ]) | |
157 | + ->inverseOf('taxOptions'); | |
158 | + } | |
159 | + | |
160 | + /** | |
161 | + * @return \yii\db\ActiveQuery | |
162 | + */ | |
163 | + public function getTaxOptions() | |
164 | + { | |
165 | + return $this->hasMany(TaxOption::className(), [ 'parent_id' => 'tax_option_id' ]) | |
166 | + ->inverseOf('parent'); | |
167 | + } | |
168 | + | |
169 | + /** | |
170 | + * @return \yii\db\ActiveQuery | |
171 | + */ | |
172 | + public function getTaxOptionToGroups() | |
173 | + { | |
174 | + return $this->hasMany(TaxOptionToGroup::className(), [ 'tax_option_id' => 'tax_option_id' ]) | |
175 | + ->inverseOf('taxOption'); | |
176 | + } | |
177 | + | |
178 | + /** | |
179 | + * @return \yii\db\ActiveQuery | |
180 | + */ | |
181 | + public function getTaxOptionToOptions() | |
182 | + { | |
183 | + return $this->hasMany(TaxOptionToOption::className(), [ 'tax_option1_id' => 'tax_option_id' ]) | |
184 | + ->inverseOf('taxOption1'); | |
185 | + } | |
186 | + | |
187 | + /** | |
188 | + * @return \yii\db\ActiveQuery | |
189 | + */ | |
190 | + public function getTaxOptionToOptions0() | |
191 | + { | |
192 | + return $this->hasMany(TaxOptionToOption::className(), [ 'tax_option2_id' => 'tax_option_id' ]) | |
193 | + ->inverseOf('taxOption2'); | |
194 | + } | |
195 | + | |
196 | + public function getTaxValueString() | |
197 | + { | |
198 | + return $this->name; | |
199 | + } | |
200 | + | |
201 | + /** | |
202 | + */ | |
203 | + public function getValue() | |
204 | + { | |
205 | + return $this->name; | |
206 | + } | |
207 | + public function setValue($value) | |
208 | + { | |
209 | + return $this->name = $value; | |
210 | + } | |
211 | + /** | |
212 | + */ | |
213 | + public function getValueRenderFlash() | |
214 | + { | |
215 | + return $this->name; | |
216 | + } | |
217 | + | |
218 | + /** | |
219 | + */ | |
220 | + public function getValueRenderHTML() | |
221 | + { | |
222 | + return $this->name; | |
223 | + } | |
224 | + | |
225 | + /** | |
226 | + * @return \yii\db\ActiveQuery | |
227 | + */ | |
228 | + public function getValues() | |
229 | + { | |
230 | + if ($valueClass = $this->getValueModelName()) { | |
231 | + return $this->hasMany($valueClass, [ 'tax_option_id' => 'tax_option_id' ]) | |
232 | + ->inverseOf('taxOption') | |
233 | + ->cascadeOnDelete(); | |
234 | + } | |
235 | + } | |
236 | + | |
237 | + public function beforeSave($insert) | |
238 | + { | |
239 | + if (parent::beforeSave($insert)) { | |
240 | + | |
241 | + if (empty($this->parent_id)) { | |
242 | + $this->parent_id = 0; | |
243 | + } | |
244 | + | |
245 | + return true; | |
246 | + } | |
247 | + return false; | |
248 | + } | |
249 | + | |
250 | + public function getImageFile() | |
251 | + { | |
252 | + return empty($this->image) ? null : Yii::getAlias('@imagesDir/tax_option/' . $this->image); | |
253 | + } | |
254 | + | |
255 | + public function getImageUrl() | |
256 | + { | |
257 | + return empty($this->image) ? null : Yii::getAlias('@imagesUrl/tax_option/' . $this->image); | |
258 | + } | |
259 | + | |
260 | + /** | |
261 | + * @return ActiveQuery | |
262 | + */ | |
263 | + public function getProducts() | |
264 | + { | |
265 | + return $this->hasMany(Product::className(), [ 'product_id' => 'product_id' ]) | |
266 | + ->viaTable('product_option', [ 'option_id' => 'tax_option_id' ]); | |
267 | + } | |
222 | 268 | } |
223 | -} | ... | ... |
console/controllers/SiteMapController.php
... | ... | @@ -10,6 +10,7 @@ |
10 | 10 | use frontend\models\ProductFrontendSearch; |
11 | 11 | use Yii; |
12 | 12 | use common\models\Page; |
13 | + use yii\db\Query; | |
13 | 14 | use yii\helpers\ArrayHelper; |
14 | 15 | use yii\helpers\Console; |
15 | 16 | use yii\helpers\Url; |
... | ... | @@ -24,6 +25,8 @@ |
24 | 25 | private $urlList = [ 'http://www.linija-svitla.ua/' ]; |
25 | 26 | private $count = 1; |
26 | 27 | |
28 | + private $addedFilters = []; | |
29 | + | |
27 | 30 | public function checkFilter($category, $filter) |
28 | 31 | { |
29 | 32 | $productModel = new ProductFrontendSearch(); |
... | ... | @@ -65,7 +68,14 @@ |
65 | 68 | [ |
66 | 69 | 'not like', |
67 | 70 | 'meta', |
68 | - '%noindex%', | |
71 | + 'noindex', | |
72 | + ] | |
73 | + ) | |
74 | + ->andWhere( | |
75 | + [ | |
76 | + '!=', | |
77 | + 'url', | |
78 | + '/', | |
69 | 79 | ] |
70 | 80 | ) |
71 | 81 | ->all(); |
... | ... | @@ -87,6 +97,7 @@ |
87 | 97 | public function getCategories() |
88 | 98 | { |
89 | 99 | return Category::find() |
100 | + ->with('brands') | |
90 | 101 | ->all(); |
91 | 102 | } |
92 | 103 | |
... | ... | @@ -127,6 +138,16 @@ |
127 | 138 | 'tax_group.is_filter' => true, |
128 | 139 | ] |
129 | 140 | ) |
141 | + ->joinWith('products') | |
142 | + ->andWhere( | |
143 | + [ | |
144 | + | |
145 | + 'product.product_id' => ( new Query() )->select(['pid' => 'product.product_id']) | |
146 | + ->from('product')->join('INNER JOIN', 'product_variant', 'product.product_id = product_variant.product_id') | |
147 | + ->where(['!=','product_variant.stock',0]) | |
148 | + | |
149 | + ] | |
150 | + ) | |
130 | 151 | ->all(); |
131 | 152 | |
132 | 153 | } |
... | ... | @@ -237,18 +258,16 @@ |
237 | 258 | $this->stdout('Add brands' . "\n", Console::FG_BLUE); |
238 | 259 | |
239 | 260 | foreach ($this->getCategories() as $category) { |
240 | - foreach ($this->getBrands($category) as $brand) { | |
241 | - if ($this->checkFilter($category, [ 'brands' => [ $brand->brand_id ] ])) { | |
242 | - $url = Url::to( | |
243 | - [ | |
244 | - 'catalog/category', | |
245 | - 'category' => $category, | |
246 | - 'filters' => [ 'brands' => [ $brand->alias ] ], | |
247 | - ], | |
248 | - true | |
249 | - ); | |
250 | - $this->createRow($url, 0.8, $content); | |
251 | - } | |
261 | + foreach ($category->brands as $brand) { | |
262 | + $url = Url::to( | |
263 | + [ | |
264 | + 'catalog/category', | |
265 | + 'category' => $category, | |
266 | + 'filters' => [ 'brands' => [ $brand->alias ] ], | |
267 | + ], | |
268 | + true | |
269 | + ); | |
270 | + $this->createRow($url, 0.8, $content); | |
252 | 271 | } |
253 | 272 | } |
254 | 273 | |
... | ... | @@ -263,6 +282,7 @@ |
263 | 282 | ], |
264 | 283 | true |
265 | 284 | ); |
285 | + $this->addedFilters[] = $url; | |
266 | 286 | $this->createRow($url, 0.8, $content); |
267 | 287 | } |
268 | 288 | |
... | ... | @@ -270,6 +290,9 @@ |
270 | 290 | |
271 | 291 | foreach ($this->getSeoLinks() as $link) { |
272 | 292 | $url = Yii::$app->urlManager->baseUrl . $link->url; |
293 | + if (in_array($url, $this->addedFilters)) { | |
294 | + continue; | |
295 | + } | |
273 | 296 | $this->createRow($url, 0.8, $content); |
274 | 297 | |
275 | 298 | } | ... | ... |