hasOne(Product::className(), ['id' => 'id_product']); } public function getTaxRate() { return $this->hasOne(TaxRate::className(), ['id' => 'id_tax_rate']); } /** * @inheritdoc */ public function rules() { return [ [['id_order', 'id_product', 'quantity'], 'required'], [['id_order', 'id_product', 'id_tax_rate'], 'integer'], [['unit'], 'string', 'max' => 255], [['quantity'], 'number', 'min' => 0], [['description'], 'safe'] ]; } /** * @inheritdoc */ public function attributeLabels() { return [ 'id' => 'ID', 'id_order' => 'Commande', 'id_product' => 'Product', 'quantity' => 'Quantité', 'unit' => 'Unité', 'id_tax_rate' => 'Taxe', 'description' => 'Description' ]; } /** * Retourne les options de base nécessaires à la fonction de recherche. * * @return array */ public static function defaultOptionsSearch() { return [ 'with' => ['taxRate'], 'join_with' => [], 'orderby' => '', 'attribute_id_producer' => '' ]; } public function afterFind() { if ($this->taxRate == null) { $this->populateRelation('taxRate', GlobalParam::getCurrentProducer()->taxRate); } parent::afterFind(); } public function getPrice() { return $this->price ; } /** * Retourne le prix du produit avec taxe */ public function getPriceWithTax() { return Price::getPriceWithTax($this->price, $this->taxRate->value); } }