Ejemplo n.º 1
0
 /**
  * Save configuration
  *
  * @return void
  */
 public function execute()
 {
     try {
         if (false == $this->_isSectionAllowed($this->getRequest()->getParam('section'))) {
             throw new \Exception(__('This section is not allowed.'));
         }
         // custom save logic
         $this->_saveSection();
         $section = $this->getRequest()->getParam('section');
         $website = $this->getRequest()->getParam('website');
         $store = $this->getRequest()->getParam('store');
         $configData = array('section' => $section, 'website' => $website, 'store' => $store, 'groups' => $this->_getGroupsForSave());
         /** @var \Magento\Backend\Model\Config $configModel  */
         $configModel = $this->_configFactory->create(array('data' => $configData));
         $configModel->save();
         $this->messageManager->addSuccess(__('You saved the configuration.'));
     } catch (\Magento\Framework\Model\Exception $e) {
         $messages = explode("\n", $e->getMessage());
         foreach ($messages as $message) {
             $this->messageManager->addError($message);
         }
     } catch (\Exception $e) {
         $this->messageManager->addException($e, __('An error occurred while saving this configuration:') . ' ' . $e->getMessage());
     }
     $this->_saveState($this->getRequest()->getPost('config_state'));
     $this->_redirect('adminhtml/system_config/edit', array('_current' => array('section', 'website', 'store')));
 }
Ejemplo n.º 2
0
 /**
  * Save configuration
  *
  * @return \Magento\Backend\Model\View\Result\Redirect
  */
 public function execute()
 {
     try {
         // custom save logic
         $this->_saveSection();
         $section = $this->getRequest()->getParam('section');
         $website = $this->getRequest()->getParam('website');
         $store = $this->getRequest()->getParam('store');
         $configData = ['section' => $section, 'website' => $website, 'store' => $store, 'groups' => $this->_getGroupsForSave()];
         /** @var \Magento\Backend\Model\Config $configModel  */
         $configModel = $this->_configFactory->create(['data' => $configData]);
         $configModel->save();
         $this->messageManager->addSuccess(__('You saved the configuration.'));
     } catch (\Magento\Framework\Model\Exception $e) {
         $messages = explode("\n", $e->getMessage());
         foreach ($messages as $message) {
             $this->messageManager->addError($message);
         }
     } catch (\Exception $e) {
         $this->messageManager->addException($e, __('An error occurred while saving this configuration:') . ' ' . $e->getMessage());
     }
     $this->_saveState($this->getRequest()->getPost('config_state'));
     /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
     $resultRedirect = $this->resultRedirectFactory->create();
     return $resultRedirect->setPath('adminhtml/system_config/edit', ['_current' => ['section', 'website', 'store'], '_nosid' => true]);
 }
Ejemplo n.º 3
0
 /**
  * Initialize objects required to render config form
  *
  * @return $this
  */
 protected function _initObjects()
 {
     $this->_configDataObject = $this->_configFactory->create(['data' => ['section' => $this->getSectionCode(), 'website' => $this->getWebsiteCode(), 'store' => $this->getStoreCode()]]);
     $this->_configData = $this->_configDataObject->load();
     $this->_fieldsetRenderer = $this->_fieldsetFactory->create();
     $this->_fieldRenderer = $this->_fieldFactory->create();
     return $this;
 }
Ejemplo n.º 4
0
 /**
  * Saves currency symbol to config
  *
  * @param  $symbols array
  * @return $this
  */
 public function setCurrencySymbolsData($symbols = array())
 {
     foreach ($this->getCurrencySymbolsData() as $code => $values) {
         if (isset($symbols[$code])) {
             if ($symbols[$code] == $values['parentSymbol'] || empty($symbols[$code])) {
                 unset($symbols[$code]);
             }
         }
     }
     if ($symbols) {
         $value['options']['fields']['customsymbol']['value'] = serialize($symbols);
     } else {
         $value['options']['fields']['customsymbol']['inherit'] = 1;
     }
     $this->_configFactory->create()->setSection(self::CONFIG_SECTION)->setWebsite(null)->setStore(null)->setGroups($value)->save();
     $this->_eventManager->dispatch('admin_system_config_changed_section_currency_before_reinit', array('website' => $this->_websiteId, 'store' => $this->_storeId));
     // reinit configuration
     $this->_coreConfig->reinit();
     $this->_storeManager->reinitStores();
     $this->clearCache();
     $this->_eventManager->dispatch('admin_system_config_changed_section_currency', array('website' => $this->_websiteId, 'store' => $this->_storeId));
     return $this;
 }