hasOne(Product::class, ['id' => 'id_product']); } public function populateProduct(Product $product) { $this->populateFieldObject('id_product', 'product', $product); } public function getOrder() { return $this->hasOne(Order::class, ['id' => 'id_order']); } public function populateOrder(Order $order) { $this->populateFieldObject('id_order', 'order', $order); } public function getTaxRate() { return $this->hasOne(TaxRate::class, ['id' => 'id_tax_rate']); } public function populateTaxRate(TaxRate $taxRate) { $this->populateFieldObject('id_tax_rate', 'taxRate', $taxRate); } /** * @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], [['price', 'invoice_price'], 'double'], [['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', 'price' => 'Prix', 'invoice_price' => 'Prix facturé', ]; } public function afterFind() { if(!$this->id_tax_rate) { $this->populateRelation('taxRate', GlobalParam::getCurrentProducer()->taxRate); } parent::afterFind(); } public function getPrice() { return $this->price; } public function getInvoicePrice() { return $this->invoice_price; } }