/** * Выводим оформление товаров * * @return mixed */ public function actionOrder() { $model = new OrderForm(); if ($model->load(Yii::$app->request->post()) && $model->validate()) { if ($model->sendEmail(Yii::$app->params['adminEmail'])) { //Yii::$app->session->setFlash('success', 'Thank you for contacting us. We will respond to you as soon as possible.'); return $this->render('success'); } else { Yii::$app->session->setFlash('error', 'There was an error sending email.'); } return $this->refresh(); } else { return $this->render('order', ['model' => $model]); } }
/** * Страница продукта */ public function actionProductBuy($id) { $item = Product::find()->with('organization', 'type')->with('agreement')->where(['id' => $id])->asArray()->one(); $item['price_format'] = Product::priceFormat($item['price']); $item['price_discount_format'] = Product::priceFormat($item['price_discount']); if (!count($item['agreement'])) { $agreement = Agreement::find()->where(["default_flag" => 1])->asArray()->one(); $item['agreement'] = $agreement; } // Загружаем в форму данные пользователя $user = Yii::$app->user->getIdentity(); $model_signup = array(); $page = $user ? 'product_buy' : 'buy_forbidden'; if ($page == 'buy_forbidden') { $model_signup = new ProfileForm(); $model_signup->setScenario('signup'); if ($model_signup->load(Yii::$app->request->post())) { if ($user = $model_signup->signup()) { if (Yii::$app->getUser()->login($user)) { return $this->redirect(Yii::$app->request->referrer); //return $this->goHome(); } } } } else { if (Yii::$app->request->post() && $user) { // Устанавливаем сценарий валидации $form = new OrderForm(); if ($form->saveOrder($user, $item, Yii::$app->request->post())) { die('true'); } else { die('false'); } } } return $this->render($page, ['item' => $item, 'user' => $user, 'model_signup' => $model_signup]); }