/** * Creates a new Order model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Order(); $session = Yii::$app->session; if ($model->load(Yii::$app->request->post())) { $model->setIsNewRecord(true); $model->createTime = date('Y-m-d H:i:s'); $model->session = $session->get('session_order'); $model->fullCost = $session->get('fullcost'); $model->save(); $fullCart = $session['cart']; $fioCart = $session['cart_fio']; if ($fullCart && $fioCart) { for ($i = 0; $i < $session->get('cards'); $i++) { $inOrder = new Inorder(); $inOrder->setIsNewRecord(true); $inOrder->orderID = $model->id; $inOrder->cardID = $session['cart'][$i]; $thisCard = Cards::find()->where(['id' => $session['cart'][$i]])->one(); $inOrder->cost = $thisCard->cost; $inOrder->fio = $session['cart_fio'][$i]; $inOrder->save(); } } $session->remove('cards'); $session->remove('session_order'); $session->remove('cart'); $session->remove('fullcost'); return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }