/** * @return \Magento\Framework\Controller\Result\Redirect */ public function execute() { $resultRedirect = $this->resultRedirectFactory->create(); $scope = $this->getRequest()->getParam('scope'); $scopeId = (int) $this->getRequest()->getParam('scope_id'); $data = $this->getRequestData(); try { $designConfigData = $this->configFactory->create($scope, $scopeId, $data); $this->designConfigRepository->save($designConfigData); $this->messageManager->addSuccess(__('You saved the configuration.')); $this->dataPersistor->clear('theme_design_config'); $returnToEdit = (bool) $this->getRequest()->getParam('back', false); $resultRedirect->setPath('theme/design_config/'); if ($returnToEdit) { $resultRedirect->setPath('theme/design_config/edit', ['scope' => $scope, 'scope_id' => $scopeId]); } return $resultRedirect; } catch (LocalizedException $e) { $messages = explode("\n", $e->getMessage()); foreach ($messages as $message) { $this->messageManager->addError(__('%1', $message)); } } catch (\Exception $e) { $this->messageManager->addException($e, __('Something went wrong while saving this configuration:') . ' ' . $e->getMessage()); } $this->dataPersistor->set('theme_design_config', $data); $resultRedirect->setPath('theme/design_config/edit', ['scope' => $scope, 'scope_id' => $scopeId]); return $resultRedirect; }
/** * Save action * * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @return \Magento\Framework\Controller\ResultInterface */ public function execute() { $data = $this->getRequest()->getPostValue(); /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ $resultRedirect = $this->resultRedirectFactory->create(); if ($data) { $data = $this->dataProcessor->filter($data); if (isset($data['is_active']) && $data['is_active'] === 'true') { $data['is_active'] = Page::STATUS_ENABLED; } if (empty($data['page_id'])) { $data['page_id'] = null; } /** @var \Magento\Cms\Model\Page $model */ $model = $this->_objectManager->create('Magento\\Cms\\Model\\Page'); $id = $this->getRequest()->getParam('page_id'); if ($id) { $model->load($id); } $model->setData($data); $this->_eventManager->dispatch('cms_page_prepare_save', ['page' => $model, 'request' => $this->getRequest()]); if (!$this->dataProcessor->validate($data)) { return $resultRedirect->setPath('*/*/edit', ['page_id' => $model->getId(), '_current' => true]); } try { $model->save(); $this->messageManager->addSuccess(__('You saved the page.')); $this->dataPersistor->clear('cms_page'); if ($this->getRequest()->getParam('back')) { return $resultRedirect->setPath('*/*/edit', ['page_id' => $model->getId(), '_current' => true]); } return $resultRedirect->setPath('*/*/'); } catch (LocalizedException $e) { $this->messageManager->addError($e->getMessage()); } catch (\Exception $e) { $this->messageManager->addException($e, __('Something went wrong while saving the page.')); } $this->dataPersistor->set('cms_page', $data); return $resultRedirect->setPath('*/*/edit', ['page_id' => $this->getRequest()->getParam('page_id')]); } return $resultRedirect->setPath('*/*/'); }
/** * Save action * * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @return \Magento\Framework\Controller\ResultInterface */ public function execute() { /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ $resultRedirect = $this->resultRedirectFactory->create(); $data = $this->getRequest()->getPostValue(); if ($data) { $id = $this->getRequest()->getParam('block_id'); if (isset($data['is_active']) && $data['is_active'] === 'true') { $data['is_active'] = Block::STATUS_ENABLED; } if (empty($data['block_id'])) { $data['block_id'] = null; } /** @var \Magento\Cms\Model\Block $model */ $model = $this->_objectManager->create('Magento\\Cms\\Model\\Block')->load($id); if (!$model->getId() && $id) { $this->messageManager->addError(__('This block no longer exists.')); return $resultRedirect->setPath('*/*/'); } $model->setData($data); try { $model->save(); $this->messageManager->addSuccess(__('You saved the block.')); $this->dataPersistor->clear('cms_block'); if ($this->getRequest()->getParam('back')) { return $resultRedirect->setPath('*/*/edit', ['block_id' => $model->getId()]); } return $resultRedirect->setPath('*/*/'); } catch (LocalizedException $e) { $this->messageManager->addError($e->getMessage()); } catch (\Exception $e) { $this->messageManager->addException($e, __('Something went wrong while saving the block.')); } $this->dataPersistor->set('cms_block', $data); return $resultRedirect->setPath('*/*/edit', ['block_id' => $this->getRequest()->getParam('block_id')]); } return $resultRedirect->setPath('*/*/'); }
/** * @return void * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ public function execute() { if ($this->getRequest()->getPostValue()) { /** @var \Magento\CatalogRule\Api\CatalogRuleRepositoryInterface $ruleRepository */ $ruleRepository = $this->_objectManager->get('Magento\\CatalogRule\\Api\\CatalogRuleRepositoryInterface'); /** @var \Magento\CatalogRule\Model\Rule $model */ $model = $this->_objectManager->create('Magento\\CatalogRule\\Model\\Rule'); try { $this->_eventManager->dispatch('adminhtml_controller_catalogrule_prepare_save', ['request' => $this->getRequest()]); $data = $this->getRequest()->getPostValue(); $id = $this->getRequest()->getParam('rule_id'); if ($id) { $model = $ruleRepository->get($id); } $validateResult = $model->validateData(new \Magento\Framework\DataObject($data)); if ($validateResult !== true) { foreach ($validateResult as $errorMessage) { $this->messageManager->addError($errorMessage); } $this->_getSession()->setPageData($data); $this->dataPersistor->set('catalog_rule', $data); $this->_redirect('catalog_rule/*/edit', ['id' => $model->getId()]); return; } if (isset($data['rule'])) { $data['conditions'] = $data['rule']['conditions']; unset($data['rule']); } $model->loadPost($data); $this->_objectManager->get('Magento\\Backend\\Model\\Session')->setPageData($data); $this->dataPersistor->set('catalog_rule', $data); $ruleRepository->save($model); $this->messageManager->addSuccess(__('You saved the rule.')); $this->_objectManager->get('Magento\\Backend\\Model\\Session')->setPageData(false); $this->dataPersistor->clear('catalog_rule'); if ($this->getRequest()->getParam('auto_apply')) { $this->getRequest()->setParam('rule_id', $model->getId()); $this->_forward('applyRules'); } else { if ($model->isRuleBehaviorChanged()) { $this->_objectManager->create('Magento\\CatalogRule\\Model\\Flag')->loadSelf()->setState(1)->save(); } if ($this->getRequest()->getParam('back')) { $this->_redirect('catalog_rule/*/edit', ['id' => $model->getId()]); return; } $this->_redirect('catalog_rule/*/'); } return; } catch (LocalizedException $e) { $this->messageManager->addError($e->getMessage()); } catch (\Exception $e) { $this->messageManager->addError(__('Something went wrong while saving the rule data. Please review the error log.')); $this->_objectManager->get('Psr\\Log\\LoggerInterface')->critical($e); $this->_objectManager->get('Magento\\Backend\\Model\\Session')->setPageData($data); $this->dataPersistor->set('catalog_rule', $data); $this->_redirect('catalog_rule/*/edit', ['id' => $this->getRequest()->getParam('rule_id')]); return; } } $this->_redirect('catalog_rule/*/'); }