예제 #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;
 }
 /**
  * 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;
     }
     return $data;
 }
 public function testCheckContactUsFormRedirectsCustomerWithWarningMessageWhenCaptchaIsRequiredAndInvalid()
 {
     $formId = 'contact_us';
     $captchaValue = 'some-value';
     $warningMessage = 'Incorrect CAPTCHA.';
     $redirectRoutePath = 'contact/index/index';
     $redirectUrl = 'http://magento.com/contacts/';
     $postData = ['name' => 'Some Name'];
     $request = $this->getMock('Magento\\Framework\\App\\Request\\Http', [], [], '', false);
     $response = $this->getMock('Magento\\Framework\\App\\Response\\Http', [], [], '', false);
     $request->expects($this->any())->method('getPost')->with(\Magento\Captcha\Helper\Data::INPUT_NAME_FIELD_VALUE, null)->willReturn([$formId => $captchaValue]);
     $request->expects($this->once())->method('getPostValue')->willReturn($postData);
     $this->redirectMock->expects($this->once())->method('redirect')->with($response, $redirectRoutePath, [])->willReturn($redirectUrl);
     $controller = $this->getMock('Magento\\Framework\\App\\Action\\Action', [], [], '', false);
     $controller->expects($this->any())->method('getRequest')->willReturn($request);
     $controller->expects($this->any())->method('getResponse')->willReturn($response);
     $this->captchaMock->expects($this->any())->method('isRequired')->willReturn(true);
     $this->captchaMock->expects($this->once())->method('isCorrect')->with($captchaValue)->willReturn(false);
     $this->captchaStringResolverMock->expects($this->once())->method('resolve')->with($request, $formId)->willReturn($captchaValue);
     $this->helperMock->expects($this->any())->method('getCaptcha')->with($formId)->willReturn($this->captchaMock);
     $this->messageManagerMock->expects($this->once())->method('addError')->with($warningMessage);
     $this->actionFlagMock->expects($this->once())->method('set')->with('', \Magento\Framework\App\Action\Action::FLAG_NO_DISPATCH, true);
     $this->dataPersistorMock->expects($this->once())->method('set')->with($formId, $postData);
     $this->checkContactUsFormObserver->execute(new \Magento\Framework\Event\Observer(['controller_action' => $controller]));
 }
 /**
  * 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();
     }
     return $this->loadedData;
 }
 /**
  * Get data
  *
  * @return array
  */
 public function getData()
 {
     if (isset($this->loadedData)) {
         return $this->loadedData;
     }
     $items = $this->collection->getItems();
     /** @var \Magento\Cms\Model\Page $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();
     }
     return $this->loadedData;
 }
 /**
  * @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();
     }
     return $this->loadedData;
 }
예제 #7
0
 /**
  * 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;
 }
예제 #8
0
 /**
  * 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('*/*/');
 }
 public function testGetDataWithNoItems()
 {
     $scope = 'websites';
     $scopeId = 1;
     $this->request->expects($this->exactly(2))->method('getParam')->willReturnMap([['scope', null, $scope], ['scope_id', null, $scopeId]]);
     $this->designConfigRepository->expects($this->once())->method('getByScope')->with($scope, $scopeId)->willReturn($this->designConfig);
     $this->designConfig->expects($this->once())->method('getExtensionAttributes')->willReturn($this->designConfigExtension);
     $this->designConfigExtension->expects($this->once())->method('getDesignConfigData')->willReturn([$this->designConfigData]);
     $this->designConfigData->expects($this->once())->method('getFieldConfig')->willReturn(['field' => 'field']);
     $this->designConfigData->expects($this->once())->method('getValue')->willReturn('value');
     $this->dataPersistor->expects($this->once())->method('get')->with('theme_design_config')->willReturn(['scope' => $scope, 'scope_id' => $scopeId]);
     $result = $this->model->getData();
     $this->assertTrue(is_array($result));
     $this->assertTrue(array_key_exists($scope, $result));
     $this->assertTrue(is_array($result[$scope]));
     $this->assertTrue(array_key_exists('scope', $result[$scope]));
     $this->assertTrue(array_key_exists('scope_id', $result[$scope]));
     $this->assertEquals($scope, $result[$scope]['scope']);
     $this->assertEquals($scopeId, $result[$scope]['scope_id']);
 }
예제 #10
0
 /**
  * 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('*/*/');
 }
예제 #11
0
 public function testSaveActionThrowsException()
 {
     $this->requestMock->expects($this->any())->method('getPostValue')->willReturn(['block_id' => 1]);
     $this->requestMock->expects($this->atLeastOnce())->method('getParam')->willReturnMap([['block_id', null, 1], ['back', null, true]]);
     $this->objectManagerMock->expects($this->atLeastOnce())->method('create')->with($this->equalTo('Magento\\Cms\\Model\\Block'))->willReturn($this->blockMock);
     $this->blockMock->expects($this->any())->method('load')->willReturnSelf();
     $this->blockMock->expects($this->any())->method('getId')->willReturn(true);
     $this->blockMock->expects($this->once())->method('setData');
     $this->blockMock->expects($this->once())->method('save')->willThrowException(new \Exception('Error message.'));
     $this->messageManagerMock->expects($this->never())->method('addSuccess');
     $this->messageManagerMock->expects($this->once())->method('addException');
     $this->dataPersistorMock->expects($this->any())->method('set')->with('cms_block', ['block_id' => 1]);
     $this->resultRedirect->expects($this->atLeastOnce())->method('setPath')->with('*/*/edit', ['block_id' => $this->blockId])->willReturnSelf();
     $this->assertSame($this->resultRedirect, $this->saveController->execute());
 }
 public function testSaveWithException()
 {
     $scope = 'sadfa';
     $scopeId = 0;
     $this->redirectFactory->expects($this->once())->method('create')->willReturn($this->redirect);
     $this->request->expects($this->exactly(2))->method('getParam')->withConsecutive(['scope'], ['scope_id'])->willReturnOnConsecutiveCalls($scope, $scopeId);
     $this->request->expects($this->once())->method('getParams')->willReturn(['header_default_title' => 'Default title']);
     $this->request->expects($this->once())->method('getFiles')->willReturn($this->fileParams);
     $this->fileParams->expects($this->once())->method('toArray')->willReturn(['header_logo' => ['tmp_name' => '', 'error' => 4]]);
     $this->configFactory->expects($this->once())->method('create')->with($scope, $scopeId, ['header_default_title' => 'Default title'])->willReturn($this->designConfig);
     $exception = new \Exception(__('Exception message'));
     $this->designConfigRepository->expects($this->once())->method('save')->with($this->designConfig)->willThrowException($exception);
     $this->messageManager->expects($this->once())->method('addException')->with($exception, 'Something went wrong while saving this configuration: Exception message');
     $this->dataPersistor->expects($this->once())->method('set')->with('theme_design_config', ['header_default_title' => 'Default title']);
     $this->redirect->expects($this->once())->method('setPath')->with('theme/design_config/edit', ['scope' => $scope, 'scope_id' => $scopeId]);
     $this->assertSame($this->redirect, $this->controller->execute());
 }
예제 #13
0
 public function testExecuteValidPost()
 {
     $post = ['name' => 'Name', 'comment' => 'Comment', 'email' => '*****@*****.**', 'hideit' => null];
     $this->dataPersistorMock->expects($this->once())->method('clear')->with('contact_us');
     $this->requestMock->expects($this->any())->method('getPostValue')->willReturn($post);
     $transport = $this->getMock('\\Magento\\Framework\\Mail\\TransportInterface', [], [], '', false);
     $this->transportBuilderMock->expects($this->once())->method('setTemplateIdentifier')->will($this->returnSelf());
     $this->transportBuilderMock->expects($this->once())->method('setTemplateOptions')->with(['area' => \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE, 'store' => \Magento\Store\Model\Store::DEFAULT_STORE_ID])->will($this->returnSelf());
     $this->transportBuilderMock->expects($this->once())->method('setTemplateVars')->will($this->returnSelf());
     $this->transportBuilderMock->expects($this->once())->method('setFrom')->will($this->returnSelf());
     $this->transportBuilderMock->expects($this->once())->method('addTo')->will($this->returnSelf());
     $this->transportBuilderMock->expects($this->once())->method('setReplyTo')->with($post['email'])->will($this->returnSelf());
     $this->transportBuilderMock->expects($this->once())->method('getTransport')->willReturn($transport);
     $transport->expects($this->once())->method('sendMessage');
     $this->inlineTranslationMock->expects($this->once())->method('resume');
     $this->inlineTranslationMock->expects($this->once())->method('suspend');
     $this->controller->execute();
 }
예제 #14
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/*/');
 }
예제 #15
0
파일: Eav.php 프로젝트: rafaelstz/magento2
 /**
  * Resolve data persistence
  *
  * @param array $data
  * @return array
  */
 private function resolvePersistentData(array $data)
 {
     $persistentData = (array) $this->dataPersistor->get('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;
 }