[ 'class' => ArtboxTreeBehavior::className(), 'keyNameGroup' => null, 'keyNamePath' => 'path', ], 'slug' => [ 'class' => RuSlug::className(), 'in_attribute' => 'name', 'out_attribute' => 'alias', 'translit' => true ], 'artboxsynonym' => [ 'class' => ArtboxSynonymBehavior::className(), 'keyNameValue' => 'category_name_id', 'valueModel' => CategoryName::className(), 'valueOptionId' => 'category_id', 'valueFields' => [ // postKey => DBFieldName 'name' => 'value' ] ], [ 'class' => relationBehavior::className(), 'relations' => [ 'product_categories' => 'entity2', // Products of category 'tax_group_to_category' => 'entity2', ] ], ]; } /** * @inheritdoc */ public static function tableName() { return 'category'; } /** * @inheritdoc */ public function rules() { return [ [['name'], 'string'], [['parent_id', 'depth', 'category_name_id', 'product_unit_id'], 'integer'], [['path', 'meta_desc', 'seo_text'], 'string'], [['meta_title'], 'string', 'max' => 255], [['meta_robots'], 'string', 'max' => 50], [['alias', 'name'], 'string', 'max' => 250], [['populary'], 'boolean'], [['group_to_category'], 'safe'], [['category_name_id'], 'exist', 'skipOnError' => true, 'targetClass' => CategoryName::className(), 'targetAttribute' => ['category_name_id' => 'category_name_id']], // [['image'], 'file', 'skipOnEmpty' => false, 'extensions' => 'png, jpg, gif'], // [['product_unit_id'], 'exist', 'skipOnError' => true, 'targetClass' => ProductUnit::className(), 'targetAttribute' => ['product_unit_id' => 'product_unit_id']], ]; } /** * @inheritdoc */ public function attributeLabels() { return [ 'category_id' => Yii::t('product', 'Category ID'), 'parent_id' => Yii::t('product', 'Parent ID'), 'path' => Yii::t('product', 'Path'), 'depth' => Yii::t('product', 'Depth'), 'image' => Yii::t('product', 'Image'), 'meta_title' => Yii::t('product', 'Meta Title'), 'meta_desc' => Yii::t('product', 'Meta Desc'), 'meta_robots' => Yii::t('product', 'Meta Robots'), 'seo_text' => Yii::t('product', 'Seo Text'), 'product_unit_id' => Yii::t('product', 'Product Unit ID'), 'alias' => Yii::t('product', 'Alias'), 'populary' => Yii::t('product', 'Populary'), 'name' => Yii::t('product', 'Name'), ]; } public static function find() { return new CategoryQuery(get_called_class()); } /** * @return \yii\db\ActiveQuery */ public function getProductUnit() { return $this->hasOne(ProductUnit::className(), ['product_unit_id' => 'product_unit_id']); } /** * @return \yii\db\ActiveQuery */ public function getCategoryNames() { return $this->hasMany(CategoryName::className(), ['category_id' => 'category_id']); } /** * @return \yii\db\ActiveQuery */ public function getProductCategories() { return $this->hasMany(ProductCategory::className(), ['category_id' => 'category_id']); } public function getTaxGroups() { return $this->getRelations('tax_group_to_category'); } public function beforeSave($insert) { if (parent::beforeSave($insert)) { if (empty($this->parent_id)) $this->parent_id = 0; return true; } return false; } public function getCategoryName() { return $this->hasOne(CategoryName::className(), ['category_name_id' => 'category_name_id']); } public function getName() { return empty($this->categoryName) ? null : $this->categoryName->value; } }