public function update(AdminAction $adminAction) { /** * @var $model CmsTree */ $model = $this->model; $relatedModel = $model->relatedPropertiesModel; $rr = new RequestResponse(); if (\Yii::$app->request->isAjax && !\Yii::$app->request->isPjax) { $model->load(\Yii::$app->request->post()); $relatedModel->load(\Yii::$app->request->post()); return \yii\widgets\ActiveForm::validateMultiple([$model, $relatedModel]); } if ($rr->isRequestPjaxPost()) { $model->load(\Yii::$app->request->post()); $relatedModel->load(\Yii::$app->request->post()); if ($model->save() && $relatedModel->save()) { \Yii::$app->getSession()->setFlash('success', \Yii::t('skeeks/cms', 'Saved')); if (\Yii::$app->request->post('submit-btn') == 'apply') { } else { return $this->redirect($this->indexUrl); } $model->refresh(); } else { $errors = []; if ($model->getErrors()) { foreach ($model->getErrors() as $error) { $errors[] = implode(', ', $error); } } \Yii::$app->getSession()->setFlash('error', \Yii::t('skeeks/cms', 'Could not save') . $errors); } } return $this->render('_form', ['model' => $model, 'relatedModel' => $relatedModel]); }
public function update() { $rr = new RequestResponse(); $model = $this->model; if ($post = \Yii::$app->request->post()) { $model->load($post); } $handler = $model->handler; if ($handler) { if ($post = \Yii::$app->request->post()) { $handler->load($post); } } if ($rr->isRequestPjaxPost()) { if (!\Yii::$app->request->post($this->notSubmitParam)) { if ($rr->isRequestPjaxPost()) { $model->component_settings = $handler->toArray(); $handler->load(\Yii::$app->request->post()); if ($model->load(\Yii::$app->request->post()) && $model->validate() && $handler->validate()) { $model->save(); \Yii::$app->getSession()->setFlash('success', \Yii::t('skeeks/cms', 'Saved')); if (\Yii::$app->request->post('submit-btn') == 'apply') { } else { return $this->redirect($this->indexUrl); } $model->refresh(); } } } } return $this->render('_form', ['model' => $model, 'handler' => $handler]); }
public function actionIndex() { $rr = new RequestResponse(); $classComponent = \Yii::$app->request->get('component'); $classComponentSettings = (string) \Yii::$app->request->get('settings'); if ($classComponentSettings) { $classComponentSettings = unserialize(StringHelper::base64DecodeUrl($classComponentSettings)); } /** * @var $component \skeeks\cms\relatedProperties\PropertyType; */ $component = new $classComponent(); try { $component->attributes = $classComponentSettings; } catch (\Exception $e) { } if (\Yii::$app->request->isAjax && !\Yii::$app->request->isPjax) { return $rr->ajaxValidateForm($component); } $forSave = ""; if ($rr->isRequestPjaxPost()) { if ($component->load(\Yii::$app->request->post())) { \Yii::$app->session->setFlash('success', 'Сохранено'); $forSave = StringHelper::base64EncodeUrl(serialize($component->attributes)); } else { \Yii::$app->session->setFlash('error', 'Ошибка'); } } return $this->render($this->action->id, ["component" => $component, "forSave" => $forSave]); }
public function update() { /** * @var $model SourceMessage */ $model = $this->model; $model->initMessages(); $rr = new RequestResponse(); if (\Yii::$app->request->isAjax && !\Yii::$app->request->isPjax) { Model::loadMultiple($model->messages, \Yii::$app->getRequest()->post()); return Model::validateMultiple($model->messages); //return $rr->ajaxValidateForm($model); } if ($rr->isRequestPjaxPost()) { if (Model::loadMultiple($model->messages, \Yii::$app->getRequest()->post()) && Model::validateMultiple($model->messages)) { $model->saveMessages(); //\Yii::$app->getSession()->setFlash('success', \Yii::t('app','Saved')); if (\Yii::$app->request->post('submit-btn') == 'apply') { } else { return $this->redirect($this->indexUrl); } } else { //\Yii::$app->getSession()->setFlash('error', \Yii::t('app','Could not save')); } } return $this->render('_form', ['model' => $model]); }
public function run() { $modelClassName = $this->controller->modelClassName; $model = new $modelClassName(); $scenarios = $model->scenarios(); if ($scenarios && $this->modelScenario) { if (isset($scenarios[$this->modelScenario])) { $model->scenario = $this->modelScenario; } } $rr = new RequestResponse(); if (\Yii::$app->request->isAjax && !\Yii::$app->request->isPjax) { return $rr->ajaxValidateForm($model); } if ($rr->isRequestPjaxPost()) { if ($model->load(\Yii::$app->request->post()) && $model->save($this->modelValidate)) { \Yii::$app->getSession()->setFlash('success', \Yii::t('app', 'Saved')); if (\Yii::$app->request->post('submit-btn') == 'apply') { return $this->controller->redirect(UrlHelper::constructCurrent()->setCurrentRef()->enableAdmin()->setRoute($this->controller->modelDefaultAction)->normalizeCurrentRoute()->addData([$this->controller->requestPkParamName => $model->{$this->controller->modelPkAttribute}])->toString()); } else { return $this->controller->redirect($this->controller->indexUrl); } } else { \Yii::$app->getSession()->setFlash('error', \Yii::t('app', 'Could not save')); } } $this->viewParams = ['model' => $model]; return parent::run(); }
public function run() { $model = $this->controller->model; $scenarios = $model->scenarios(); if ($scenarios && $this->modelScenario) { if (isset($scenarios[$this->modelScenario])) { $model->scenario = $this->modelScenario; } } $rr = new RequestResponse(); if (\Yii::$app->request->isAjax && !\Yii::$app->request->isPjax) { return $rr->ajaxValidateForm($model); } if ($rr->isRequestPjaxPost()) { if ($model->load(\Yii::$app->request->post()) && $model->save($this->modelValidate)) { \Yii::$app->getSession()->setFlash('success', \Yii::t('app', 'Saved')); if (\Yii::$app->request->post('submit-btn') == 'apply') { } else { return $this->controller->redirect($this->controller->indexUrl); } $model->refresh(); } else { \Yii::$app->getSession()->setFlash('error', \Yii::t('app', 'Could not save')); } } $this->viewParams = ['model' => $model]; return parent::run(); }
public function run() { /** * @var $contentElement CmsContentElement */ $contentElement = $this->controller->model; $model = ShopProduct::find()->where(['id' => $contentElement->id])->one(); $productPrices = []; if (!$model) { $model = new ShopProduct(['id' => $contentElement->id]); } else { if ($typePrices = ShopTypePrice::find()->where(['!=', 'def', Cms::BOOL_Y])->all()) { foreach ($typePrices as $typePrice) { $productPrice = ShopProductPrice::find()->where(['product_id' => $model->id, 'type_price_id' => $typePrice->id])->one(); if (!$productPrice) { $productPrice = new ShopProductPrice(['product_id' => $model->id, 'type_price_id' => $typePrice->id]); } if ($post = \Yii::$app->request->post()) { $data = ArrayHelper::getValue($post, 'prices.' . $typePrice->id); $productPrice->load($data, ""); } $productPrices[] = $productPrice; } } } $rr = new RequestResponse(); if (\Yii::$app->request->isAjax && !\Yii::$app->request->isPjax) { return $rr->ajaxValidateForm($model); } if ($rr->isRequestPjaxPost()) { /** * @var $productPrice ShopProductPrice */ foreach ($productPrices as $productPrice) { if ($productPrice->save()) { } else { \Yii::$app->getSession()->setFlash('error', \skeeks\cms\shop\Module::t('app', 'Check the correctness of the prices')); } } if ($model->load(\Yii::$app->request->post()) && $model->save()) { \Yii::$app->getSession()->setFlash('success', 'Saved'); if (\Yii::$app->request->post('submit-btn') == 'apply') { } else { return $this->controller->redirect($this->controller->indexUrl); } $model->refresh(); } else { \Yii::$app->getSession()->setFlash('error', \skeeks\cms\shop\Module::t('app', 'Failed to save')); } } $this->viewParams = ['model' => $model, 'productPrices' => $productPrices]; return parent::run(); }
public function update(AdminAction $adminAction) { /** * @var $model CmsUser */ $model = $this->model; $relatedModel = $model->relatedPropertiesModel; $passwordChange = new PasswordChangeForm(['user' => $model]); $passwordChange->scenario = PasswordChangeForm::SCENARION_NOT_REQUIRED; $rr = new RequestResponse(); if (\Yii::$app->request->isAjax && !\Yii::$app->request->isPjax) { $model->load(\Yii::$app->request->post()); $relatedModel->load(\Yii::$app->request->post()); $passwordChange->load(\Yii::$app->request->post()); return \yii\widgets\ActiveForm::validateMultiple([$model, $relatedModel, $passwordChange]); } if ($rr->isRequestPjaxPost()) { $model->load(\Yii::$app->request->post()); $relatedModel->load(\Yii::$app->request->post()); $passwordChange->load(\Yii::$app->request->post()); if ($model->save() && $relatedModel->save()) { \Yii::$app->getSession()->setFlash('success', \Yii::t('skeeks/cms', 'Saved')); if ($passwordChange->new_password) { if (!$passwordChange->changePassword()) { \Yii::$app->getSession()->setFlash('error', "Пароль не изменен"); } } if (\Yii::$app->request->post('submit-btn') == 'apply') { } else { return $this->redirect($this->indexUrl); } $model->refresh(); } else { $errors = []; if ($model->getErrors()) { foreach ($model->getErrors() as $error) { $errors[] = implode(', ', $error); } } \Yii::$app->getSession()->setFlash('error', \Yii::t('skeeks/cms', 'Could not save') . ". " . implode($errors)); } } return $this->render('_form', ['model' => $model, 'relatedModel' => $relatedModel, 'passwordChange' => $passwordChange]); }
public function run() { $rr = new RequestResponse(); $errors = []; if ($post = \Yii::$app->request->post()) { $this->shopFuser->load($post); $this->shopFuser->save(); } $this->shopBuyer = $this->shopFuser->personType->createModelShopBuyer(); $shopBuyer = $this->shopBuyer; if ($shopBuyer) { if ($post = \Yii::$app->request->post()) { $this->shopBuyer->load($post); $this->shopBuyer->relatedPropertiesModel->load($post); } } if ($rr->isRequestPjaxPost()) { if (!\Yii::$app->request->post($this->notSubmitParam)) { if ($this->shopFuser->validate() && $this->shopBuyer->validate() && $this->shopBuyer->relatedPropertiesModel->validate()) { if ($this->shopBuyer->isNewRecord) { if (!$this->shopBuyer->save()) { throw new Exception('Not save buyer'); } } if (!$this->shopBuyer->relatedPropertiesModel->save()) { throw new Exception('Not save buyer data'); } $this->shopFuser->buyer_id = $this->shopBuyer->id; $newOrder = ShopOrder::createOrderByFuser($this->shopFuser); $orderUrl = $newOrder->publicUrl; $this->view->registerJs(<<<JS location.href='{$orderUrl}'; JS ); } else { /*print_r($this->shopFuser->firstErrors); print_r($this->shopBuyer->firstErrors); print_r($this->shopBuyer->relatedPropertiesModel->firstErrors);*/ } } } return $this->render($this->viewFile); }
public function createOrder() { $cmsUser = null; if ($userId = \Yii::$app->request->get('cmsUserId')) { $cmsUser = CmsUser::findOne($userId); } if ($cmsUser) { /** * @var $shopFuser ShopFuser */ $shopFuser = ShopFuser::getInstanceByUser($cmsUser); $model = $shopFuser; $rr = new RequestResponse(); if (\Yii::$app->request->isAjax && !\Yii::$app->request->isPjax) { $model->scenario = ShopFuser::SCENARIO_CREATE_ORDER; return $rr->ajaxValidateForm($model); } if ($rr->isRequestPjaxPost()) { try { if ($model->load(\Yii::$app->request->post()) && $model->save()) { $model->scenario = ShopFuser::SCENARIO_CREATE_ORDER; if ($model->validate()) { $order = ShopOrder::createOrderByFuser($model); if (!$order->isNewRecord) { \Yii::$app->getSession()->setFlash('success', \Yii::t('skeeks/shop/app', 'The order #{order_id} created successfully', ['order_id' => $order->id])); if (\Yii::$app->request->post('submit-btn') == 'apply') { return $this->redirect(UrlHelper::constructCurrent()->setCurrentRef()->enableAdmin()->setRoute($this->modelDefaultAction)->normalizeCurrentRoute()->addData([$this->requestPkParamName => $order->id])->toString()); } else { return $this->redirect($this->indexUrl); } } else { throw new Exception(\Yii::t('skeeks/shop/app', 'Incorrect data of the new order') . ": " . array_shift($order->getFirstErrors())); } } else { throw new Exception(\Yii::t('skeeks/shop/app', 'Not enogh data for ordering') . ": " . array_shift($model->getFirstErrors())); } } else { throw new Exception(\Yii::t('skeeks/shop/app', 'Could not save')); } } catch (\Exception $e) { \Yii::$app->getSession()->setFlash('error', $e->getMessage()); } } return $this->render($this->action->id, ['cmsUser' => $cmsUser, 'shopFuser' => $model]); } else { return $this->render($this->action->id . "-select-user"); } }
public function update(AdminAction $adminAction) { /** * @var $model CmsContentElement */ $model = $this->model; $relatedModel = $model->relatedPropertiesModel; $shopProduct = ShopProduct::find()->where(['id' => $model->id])->one(); $productPrices = []; if (!$shopProduct) { $shopProduct = new ShopProduct(['id' => $model->id]); $shopProduct->save(); } else { if ($typePrices = ShopTypePrice::find()->where(['!=', 'def', Cms::BOOL_Y])->all()) { foreach ($typePrices as $typePrice) { $productPrice = ShopProductPrice::find()->where(['product_id' => $shopProduct->id, 'type_price_id' => $typePrice->id])->one(); if (!$productPrice) { $productPrice = new ShopProductPrice(['product_id' => $shopProduct->id, 'type_price_id' => $typePrice->id]); } if ($post = \Yii::$app->request->post()) { $data = ArrayHelper::getValue($post, 'prices.' . $typePrice->id); $productPrice->load($data, ""); } $productPrices[] = $productPrice; } } } $rr = new RequestResponse(); if (\Yii::$app->request->isAjax && !\Yii::$app->request->isPjax) { $model->load(\Yii::$app->request->post()); $relatedModel->load(\Yii::$app->request->post()); $shopProduct->load(\Yii::$app->request->post()); return \yii\widgets\ActiveForm::validateMultiple([$model, $relatedModel, $shopProduct]); } if ($rr->isRequestPjaxPost()) { $model->load(\Yii::$app->request->post()); $relatedModel->load(\Yii::$app->request->post()); $shopProduct->load(\Yii::$app->request->post()); /** * @var $productPrice ShopProductPrice */ foreach ($productPrices as $productPrice) { if ($productPrice->save()) { } else { \Yii::$app->getSession()->setFlash('error', \Yii::t('skeeks/shop/app', 'Check the correctness of the prices')); } } if ($model->save() && $relatedModel->save() && $shopProduct->save()) { \Yii::$app->getSession()->setFlash('success', \Yii::t('skeeks/shop/app', 'Saved')); if (\Yii::$app->request->post('submit-btn') == 'apply') { } else { return $this->redirect($this->indexUrl); } $model->refresh(); } else { $errors = []; if ($model->getErrors()) { foreach ($model->getErrors() as $error) { $errors[] = implode(', ', $error); } } \Yii::$app->getSession()->setFlash('error', \Yii::t('skeeks/shop/app', 'Could not save') . $errors); } } if (!$shopProduct->baseProductPrice) { $baseProductPrice = new ShopProductPrice(['type_price_id' => \Yii::$app->shop->baseTypePrice->id, 'currency_code' => \Yii::$app->money->currencyCode, 'product_id' => $model->id]); $baseProductPrice->save(); } return $this->render('_form', ['model' => $model, 'relatedModel' => $relatedModel, 'shopProduct' => $shopProduct, 'productPrices' => $productPrices, 'baseProductPrice' => $shopProduct->getBaseProductPrice()->one()]); }