public function actionGetdiscount() { $code = rand(); $value = 0.95; $discount = new Discounts(); $discount->code = $code; $discount->value = $value; $discount->save(); return $this->actionAccount($code); }
/** * Creates a new Discounts model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Discounts(); $session = Yii::$app->session; $session->open(); $post = Yii::$app->request->post(); if (Yii::$app->request->isPost) { $post['Discounts']['providers_id'] = $session['providerIdFullName']; $post['Discounts']['price_type_id'] = $session['typePrice']; $res = $model->load($post); } $types = \app\models\GoodsType::find()->all(); $arTypes = ['' => ' - Не выбран тип товара -']; foreach ($types as $type) { $arTypes[$type->type] = $type->name; } if ($model->load($post) && $model->save()) { return $this->redirect(['index']); } else { return $this->render('create', ['model' => $model, 'arTypes' => $arTypes, 'providerName' => $session['providerIdFullNameName'], 'typePriceName' => $session['typePriceName']]); } }