public function calculateDelivery() { $delivery = \Yii::$app->request->get('delivery'); $this->weight = Products::find()->where(['id' => array_keys(\Yii::$app->getModule('checkout')->cart->positions)])->sum('weight'); switch ($delivery) { case 2: $this->nDelivery($this->weight); break; case 1: $this->nDelivery($this->weight); $this->pDelivery(); break; } }
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(); } } }
/** * @return \yii\db\ActiveQuery */ public function getProduct() { return $this->hasOne(Products::className(), ['id' => 'product_id']); }
public function getProduct() { return $this->hasOne(\stronglab\checkout\models\Products::className(), ['id' => 'model_id']); }