SaveImgBehavior::className(), 'fields' => [ [ 'name' => 'image', 'directory' => 'tax_option', ], ], ], 'artboxtree' => [ 'class' => ArtboxTreeBehavior::className(), 'keyNameGroup' => 'tax_group_id', ], 'language' => [ 'class' => LanguageBehavior::className(), ], ]; } /** * @inheritdoc */ public static function tableName() { return '{{%tax_option}}'; } /** * @inheritdoc */ public function rules() { return [ [ [ 'tax_group_id', ], 'required', ], [ [ 'tax_group_id', 'parent_id', 'sort', ], 'integer', ], [ [ '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'), 'sort' => Yii::t('app', 'Sort'), 'image' => Yii::t('product', 'Image'), ]; } public static function find() { return new TaxOptionQuery(get_called_class()); } /** * @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'); } public function beforeSave($insert) { if(parent::beforeSave($insert)) { if(empty( $this->parent_id )) { $this->parent_id = 0; } return true; } return false; } public function getProducts() { return $this->hasMany(Product::className(), [ 'product_id' => 'product_id' ]) ->viaTable('product_option', [ 'option_id' => 'tax_option_id' ]); } }