Beispiel #1
0
 /**
  * @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;
 }
Beispiel #2
0
 /**
  * Load data
  *
  * @param string $scope
  * @param string $scopeId
  * @return array
  */
 protected function loadData($scope, $scopeId)
 {
     $designConfig = $this->designConfigRepository->getByScope($scope, $scopeId);
     $fieldsData = $designConfig->getExtensionAttributes()->getDesignConfigData();
     $data = [];
     foreach ($fieldsData as $fieldData) {
         $data[$scope][$fieldData->getFieldConfig()['field']] = $fieldData->getValue();
     }
     $storedData = $this->dataPersistor->get('theme_design_config');
     if (isset($storedData['scope']) && isset($storedData['scope_id']) && $storedData['scope'] == $scope && $storedData['scope_id'] == $scopeId) {
         $data[$scope] = $storedData;
         $this->dataPersistor->clear('theme_design_config');
     }
     return $data;
 }
Beispiel #3
0
 /**
  * Get data
  *
  * @return array
  */
 public function getData()
 {
     if (isset($this->loadedData)) {
         return $this->loadedData;
     }
     $items = $this->collection->getItems();
     /** @var \Magento\Cms\Model\Block $block */
     foreach ($items as $block) {
         $this->loadedData[$block->getId()] = $block->getData();
     }
     $data = $this->dataPersistor->get('cms_block');
     if (!empty($data)) {
         $block = $this->collection->getNewEmptyItem();
         $block->setData($data);
         $this->loadedData[$block->getId()] = $block->getData();
         $this->dataPersistor->clear('cms_block');
     }
     return $this->loadedData;
 }
Beispiel #4
0
 /**
  * Get data
  *
  * @return array
  */
 public function getData()
 {
     if (isset($this->loadedData)) {
         return $this->loadedData;
     }
     $items = $this->collection->getItems();
     /** @var $page \Magento\Cms\Model\Page */
     foreach ($items as $page) {
         $this->loadedData[$page->getId()] = $page->getData();
     }
     $data = $this->dataPersistor->get('cms_page');
     if (!empty($data)) {
         $page = $this->collection->getNewEmptyItem();
         $page->setData($data);
         $this->loadedData[$page->getId()] = $page->getData();
         $this->dataPersistor->clear('cms_page');
     }
     return $this->loadedData;
 }
 /**
  * Get data
  *
  * @return array
  */
 public function getData()
 {
     if (isset($this->loadedData)) {
         return $this->loadedData;
     }
     $items = $this->collection->getItems();
     /** @var $tag \Magefan\Blog\Model\Tag */
     foreach ($items as $tag) {
         $this->loadedData[$tag->getId()] = $tag->getData();
     }
     $data = $this->dataPersistor->get('current_model');
     if (!empty($data)) {
         $tag = $this->collection->getNewEmptyItem();
         $tag->setData($data);
         $this->loadedData[$tag->getId()] = $tag->getData();
         $this->dataPersistor->clear('current_model');
     }
     return $this->loadedData;
 }
 /**
  * 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('*/*/');
 }
Beispiel #7
0
 /**
  * @return array
  */
 public function getData()
 {
     if (isset($this->loadedData)) {
         return $this->loadedData;
     }
     $items = $this->collection->getItems();
     /** @var Rule $rule */
     foreach ($items as $rule) {
         $rule->load($rule->getId());
         $this->loadedData[$rule->getId()] = $rule->getData();
     }
     $data = $this->dataPersistor->get('catalog_rule');
     if (!empty($data)) {
         $rule = $this->collection->getNewEmptyItem();
         $rule->setData($data);
         $this->loadedData[$rule->getId()] = $rule->getData();
         $this->dataPersistor->clear('catalog_rule');
     }
     return $this->loadedData;
 }
 /**
  * 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('*/*/');
 }
Beispiel #9
0
 /**
  * @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/*/');
 }
Beispiel #10
0
 /**
  * Resolve data persistence
  *
  * @param array $data
  * @return array
  */
 private function resolvePersistentData(array $data)
 {
     $persistentData = (array) $this->dataPersistor->get('catalog_product');
     $this->dataPersistor->clear('catalog_product');
     $productId = $this->locator->getProduct()->getId();
     if (empty($data[$productId][self::DATA_SOURCE_DEFAULT])) {
         $data[$productId][self::DATA_SOURCE_DEFAULT] = [];
     }
     $data[$productId] = array_replace_recursive($data[$productId][self::DATA_SOURCE_DEFAULT], $persistentData);
     return $data;
 }