true, 'targetClass' => ProductVariant::className(), 'targetAttribute' => [ 'product_variant_id' => 'id' ], ], [ [ 'stock_id' ], 'exist', 'skipOnError' => true, 'targetClass' => Stock::className(), 'targetAttribute' => [ 'stock_id' => 'id' ], ], ]; } /** * @inheritdoc */ public function attributeLabels() { return [ 'stock_id' => 'Stock ID', 'quantity' => 'Количество', 'product_variant_id' => 'Product Variant ID', 'title' => "Название", ]; } /** * @return \yii\db\ActiveQuery */ public function getProduct() { return $this->hasOne(Product::className(), [ 'id' => 'product_id' ]) ->via('variants'); } /** * @return \yii\db\ActiveQuery */ public function getProductVariant() { return $this->hasOne(ProductVariant::className(), [ 'id' => 'product_variant_id' ]); } /** * Get Stock title, tries to get from Stock lang * * @return string */ public function getTitle(): string { if (!empty( $this->title )) { return $this->title; } elseif (!empty( $this->stock )) { return $this->stock->title; } else { return ''; } } /** * Set Stock title, will be saved to Stock table * * @param mixed $value */ public function setTitle(string $value) { $this->title = $value; } /** * @return \yii\db\ActiveQuery */ public function getStock() { return $this->hasOne(Stock::className(), [ 'id' => 'stock_id' ]); } /** * @inheritdoc */ public static function primaryKey() { return [ "stock_id", "product_variant_id", ]; } }