diff --git a/common/modules/rubrication/models/TaxOption.php b/common/modules/rubrication/models/TaxOption.php index 48a9b03..3d5dbd2 100755 --- a/common/modules/rubrication/models/TaxOption.php +++ b/common/modules/rubrication/models/TaxOption.php @@ -1,223 +1,268 @@ [ - 'class' => ArtboxTreeBehavior::className(), - 'keyNameGroup' => 'tax_group_id', - ], - 'slug' => [ - 'class' => 'common\behaviors\Slug', - 'in_attribute' => 'name', - 'out_attribute' => 'alias', - 'translit' => true - ], - - ]; - } - + public $_items_count; + /** - * @inheritdoc - */ - public static function tableName() - { - return '{{%tax_option}}'; - } - - /** - * @inheritdoc - */ - public function rules() - { - return [ - [['tax_group_id','name'], 'required'], - [['tax_group_id', 'parent_id', 'sort', 'default_value'], 'integer'], - [['image','alias', 'value', 'synonym'], 'string', 'max' => 255], - [['tax_group_id'], 'exist', 'skipOnError' => true, 'targetClass' => TaxGroup::className(), 'targetAttribute' => ['tax_group_id' => 'tax_group_id']], - ]; - } - - /** - * @inheritdoc - */ - public function attributeLabels() - { - return [ - 'tax_option_id' => Yii::t('app', 'Tax Option ID'), - 'tax_group_id' => Yii::t('app', 'Tax Group ID'), - 'parent_id' => Yii::t('app', 'Parent ID'), - 'alias' => Yii::t('app', 'Alias'), - 'sort' => Yii::t('app', 'Sort'), - 'default_value' => Yii::t('app', 'Default Value'), - 'image' => Yii::t('product', 'Image'), - 'synonym' => Yii::t('product', 'Синоним'), - ]; - } - - public static function find() { - return new TaxOptionQuery(get_called_class()); - } - - /** - * @return \yii\db\ActiveQuery - */ - public function getTaxEntityRelations() - { - return $this->hasMany(TaxEntityRelation::className(), ['tax_option_id' => 'tax_option_id'])->inverseOf('taxOption'); - } - - - /** - * @return \yii\db\ActiveQuery - */ - public function getGroup() - { - return $this->getTaxGroup(); - } - - /** - * @return \yii\db\ActiveQuery - */ - public function getTaxGroup() - { - return $this->hasOne(TaxGroup::className(), ['tax_group_id' => 'tax_group_id'])->inverseOf('taxOptions'); - } - - /** - * @return \yii\db\ActiveQuery - */ - public function getTaxOptions() - { - return $this->hasMany(TaxOption::className(), ['parent_id' => 'tax_option_id'])->inverseOf('parent'); - } - - /** - * @return \yii\db\ActiveQuery - */ - public function getTaxOptionToGroups() - { - return $this->hasMany(TaxOptionToGroup::className(), ['tax_option_id' => 'tax_option_id'])->inverseOf('taxOption'); - } - - /** - * @return \yii\db\ActiveQuery - */ - public function getTaxOptionToOptions() - { - return $this->hasMany(TaxOptionToOption::className(), ['tax_option1_id' => 'tax_option_id'])->inverseOf('taxOption1'); - } - - /** - * @return \yii\db\ActiveQuery - */ - public function getTaxOptionToOptions0() - { - return $this->hasMany(TaxOptionToOption::className(), ['tax_option2_id' => 'tax_option_id'])->inverseOf('taxOption2'); - } - - - public function getTaxValueString(){ - return $this->name; - } - - - /** - */ - public function getValue() - { - return $this->name; - } - public function setValue($value){ - return $this->name = $value; - } - /** - */ - public function getValueRenderFlash() - { - return $this->name; - } - - /** - */ - public function getValueRenderHTML() - { - return $this->name; - } - - - - /** - * @return \yii\db\ActiveQuery - */ - public function getValues() - { - if ($valueClass = $this->getValueModelName()) - return $this->hasMany($valueClass, ['tax_option_id' => 'tax_option_id'])->inverseOf('taxOption')->cascadeOnDelete(); - } - - public function beforeSave($insert) - { - if (parent::beforeSave($insert)) { - - if (empty($this->parent_id)) - $this->parent_id = 0; - - - - return true; - } - return false; - } - - public function getImageFile() { - return empty($this->image) ? null : Yii::getAlias('@imagesDir/tax_option/'. $this->image); - } - - public function getImageUrl() - { - return empty($this->image) ? null : Yii::getAlias('@imagesUrl/tax_option/' . $this->image); + * @inheritdoc + */ + public function behaviors() + { + return [ + 'artboxtree' => [ + 'class' => ArtboxTreeBehavior::className(), + 'keyNameGroup' => 'tax_group_id', + ], + 'slug' => [ + 'class' => 'common\behaviors\Slug', + 'in_attribute' => 'name', + 'out_attribute' => 'alias', + 'translit' => true, + ], + + ]; + } + + /** + * @inheritdoc + */ + public static function tableName() + { + return '{{%tax_option}}'; + } + + /** + * @inheritdoc + */ + public function rules() + { + return [ + [ + [ + 'tax_group_id', + 'name', + ], + 'required', + ], + [ + [ + 'tax_group_id', + 'parent_id', + 'sort', + 'default_value', + ], + 'integer', + ], + [ + [ + 'image', + 'alias', + 'value', + 'synonym', + ], + 'string', + 'max' => 255, + ], + [ + [ 'tax_group_id' ], + 'exist', + 'skipOnError' => true, + 'targetClass' => TaxGroup::className(), + 'targetAttribute' => [ 'tax_group_id' => 'tax_group_id' ], + ], + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'tax_option_id' => Yii::t('app', 'Tax Option ID'), + 'tax_group_id' => Yii::t('app', 'Tax Group ID'), + 'parent_id' => Yii::t('app', 'Parent ID'), + 'alias' => Yii::t('app', 'Alias'), + 'sort' => Yii::t('app', 'Sort'), + 'default_value' => Yii::t('app', 'Default Value'), + 'image' => Yii::t('product', 'Image'), + 'synonym' => Yii::t('product', 'Синоним'), + ]; + } + + public static function find() + { + return new TaxOptionQuery(get_called_class()); + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getTaxEntityRelations() + { + return $this->hasMany(TaxEntityRelation::className(), [ 'tax_option_id' => 'tax_option_id' ]) + ->inverseOf('taxOption'); + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getGroup() + { + return $this->getTaxGroup(); + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getTaxGroup() + { + return $this->hasOne(TaxGroup::className(), [ 'tax_group_id' => 'tax_group_id' ]) + ->inverseOf('taxOptions'); + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getTaxOptions() + { + return $this->hasMany(TaxOption::className(), [ 'parent_id' => 'tax_option_id' ]) + ->inverseOf('parent'); + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getTaxOptionToGroups() + { + return $this->hasMany(TaxOptionToGroup::className(), [ 'tax_option_id' => 'tax_option_id' ]) + ->inverseOf('taxOption'); + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getTaxOptionToOptions() + { + return $this->hasMany(TaxOptionToOption::className(), [ 'tax_option1_id' => 'tax_option_id' ]) + ->inverseOf('taxOption1'); + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getTaxOptionToOptions0() + { + return $this->hasMany(TaxOptionToOption::className(), [ 'tax_option2_id' => 'tax_option_id' ]) + ->inverseOf('taxOption2'); + } + + public function getTaxValueString() + { + return $this->name; + } + + /** + */ + public function getValue() + { + return $this->name; + } + public function setValue($value) + { + return $this->name = $value; + } + /** + */ + public function getValueRenderFlash() + { + return $this->name; + } + + /** + */ + public function getValueRenderHTML() + { + return $this->name; + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getValues() + { + if ($valueClass = $this->getValueModelName()) { + return $this->hasMany($valueClass, [ 'tax_option_id' => 'tax_option_id' ]) + ->inverseOf('taxOption') + ->cascadeOnDelete(); + } + } + + public function beforeSave($insert) + { + if (parent::beforeSave($insert)) { + + if (empty($this->parent_id)) { + $this->parent_id = 0; + } + + return true; + } + return false; + } + + public function getImageFile() + { + return empty($this->image) ? null : Yii::getAlias('@imagesDir/tax_option/' . $this->image); + } + + public function getImageUrl() + { + return empty($this->image) ? null : Yii::getAlias('@imagesUrl/tax_option/' . $this->image); + } + + /** + * @return ActiveQuery + */ + public function getProducts() + { + return $this->hasMany(Product::className(), [ 'product_id' => 'product_id' ]) + ->viaTable('product_option', [ 'option_id' => 'tax_option_id' ]); + } } -} diff --git a/console/controllers/SiteMapController.php b/console/controllers/SiteMapController.php index fa3ada2..0aef135 100755 --- a/console/controllers/SiteMapController.php +++ b/console/controllers/SiteMapController.php @@ -10,6 +10,7 @@ use frontend\models\ProductFrontendSearch; use Yii; use common\models\Page; + use yii\db\Query; use yii\helpers\ArrayHelper; use yii\helpers\Console; use yii\helpers\Url; @@ -24,6 +25,8 @@ private $urlList = [ 'http://www.linija-svitla.ua/' ]; private $count = 1; + private $addedFilters = []; + public function checkFilter($category, $filter) { $productModel = new ProductFrontendSearch(); @@ -65,7 +68,14 @@ [ 'not like', 'meta', - '%noindex%', + 'noindex', + ] + ) + ->andWhere( + [ + '!=', + 'url', + '/', ] ) ->all(); @@ -87,6 +97,7 @@ public function getCategories() { return Category::find() + ->with('brands') ->all(); } @@ -127,6 +138,16 @@ 'tax_group.is_filter' => true, ] ) + ->joinWith('products') + ->andWhere( + [ + + 'product.product_id' => ( new Query() )->select(['pid' => 'product.product_id']) + ->from('product')->join('INNER JOIN', 'product_variant', 'product.product_id = product_variant.product_id') + ->where(['!=','product_variant.stock',0]) + + ] + ) ->all(); } @@ -237,18 +258,16 @@ $this->stdout('Add brands' . "\n", Console::FG_BLUE); 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 ] ], - ], - true - ); - $this->createRow($url, 0.8, $content); - } + foreach ($category->brands as $brand) { + $url = Url::to( + [ + 'catalog/category', + 'category' => $category, + 'filters' => [ 'brands' => [ $brand->alias ] ], + ], + true + ); + $this->createRow($url, 0.8, $content); } } @@ -263,6 +282,7 @@ ], true ); + $this->addedFilters[] = $url; $this->createRow($url, 0.8, $content); } @@ -270,6 +290,9 @@ foreach ($this->getSeoLinks() as $link) { $url = Yii::$app->urlManager->baseUrl . $link->url; + if (in_array($url, $this->addedFilters)) { + continue; + } $this->createRow($url, 0.8, $content); } -- libgit2 0.21.4