protected function saveProducts() { $products = Products::find()->where(['id' => array_keys($this->cart->positions)])->all(); foreach ($products as $product) { if (!$product->isActive()) { continue; } $has = new OrdersHasProducts(); $has->order_id = (int) $this->id; $has->product_id = (int) $product->id; $has->quantity = (int) $product->quantity; $has->price = (int) $product->price; if ($has->save() && !$product->hold) { $product->detachBehavior('Taggable'); $product->active = Products::ACTIVE_IN_ORDER; $product->save(); } } }
public function getJunc() { return $this->hasOne(OrdersHasProducts::className(), ['product_id' => 'id']); }