Esempio n. 1
0
 /**
  * @return mixed
  */
 public function execute()
 {
     /** @var \Magento\Framework\Controller\Result\Json $resultJson */
     $resultJson = $this->jsonFactory->create();
     $error = false;
     $messages = [];
     $postItems = $this->getRequest()->getParam('items', []);
     if (!($this->getRequest()->getParam('isAjax') && count($postItems))) {
         return $resultJson->setData(['messages' => [__('Please correct the data sent.')], 'error' => true]);
     }
     foreach (array_keys($postItems) as $articleId) {
         $article = $this->articleFactory->create()->load($articleId);
         try {
             $articleData = $this->filterData($postItems[$articleId]);
             $article->addData($articleData);
             $article->save();
         } catch (\Magento\Framework\Exception\LocalizedException $e) {
             $messages[] = $this->getErrorWithArticleId($article, $e->getMessage());
             $error = true;
         } catch (\RuntimeException $e) {
             $messages[] = $this->getErrorWithArticleId($article, $e->getMessage());
             $error = true;
         } catch (\Exception $e) {
             $messages[] = $this->getErrorWithArticleId($article, __('Something went wrong while saving the page.'));
             $error = true;
         }
     }
     return $resultJson->setData(['messages' => $messages, 'error' => $error]);
 }
Esempio n. 2
0
 /**
  * {@inheritDoc}
  */
 public function execute()
 {
     $this->initLayer();
     $items = $this->getItems();
     $result = $this->jsonResultFactory->create()->setData($items);
     return $result;
 }
Esempio n. 3
0
 /**
  * Global Search Action
  *
  * @return \Magento\Framework\Controller\Result\Json
  */
 public function execute()
 {
     $items = [];
     if (!$this->_authorization->isAllowed('Magento_Backend::global_search')) {
         $items[] = ['id' => 'error', 'type' => __('Error'), 'name' => __('Access Denied'), 'description' => __('You need more permissions to do this.')];
     } else {
         if (empty($this->_searchModules)) {
             $items[] = ['id' => 'error', 'type' => __('Error'), 'name' => __('No search modules were registered'), 'description' => __('Please make sure that all global admin search modules are installed and activated.')];
         } else {
             $start = $this->getRequest()->getParam('start', 1);
             $limit = $this->getRequest()->getParam('limit', 10);
             $query = $this->getRequest()->getParam('query', '');
             foreach ($this->_searchModules as $searchConfig) {
                 if ($searchConfig['acl'] && !$this->_authorization->isAllowed($searchConfig['acl'])) {
                     continue;
                 }
                 $className = $searchConfig['class'];
                 if (empty($className)) {
                     continue;
                 }
                 $searchInstance = $this->_objectManager->create($className);
                 $results = $searchInstance->setStart($start)->setLimit($limit)->setQuery($query)->load()->getResults();
                 $items = array_merge_recursive($items, $results);
             }
         }
     }
     /** @var \Magento\Framework\Controller\Result\Json $resultJson */
     $resultJson = $this->resultJsonFactory->create();
     return $resultJson->setData($items);
 }
Esempio n. 4
0
 /**
  * Delete file from media storage
  *
  * @return \Magento\Framework\Controller\ResultInterface
  */
 public function execute()
 {
     try {
         if (!$this->getRequest()->isPost()) {
             throw new \Exception('Wrong request.');
         }
         $files = $this->getRequest()->getParam('files');
         /** @var $helper \Magento\Cms\Helper\Wysiwyg\Images */
         $helper = $this->_objectManager->get('Magento\\Cms\\Helper\\Wysiwyg\\Images');
         $path = $this->getStorage()->getSession()->getCurrentPath();
         foreach ($files as $file) {
             $file = $helper->idDecode($file);
             /** @var \Magento\Framework\Filesystem $filesystem */
             $filesystem = $this->_objectManager->get('Magento\\Framework\\Filesystem');
             $dir = $filesystem->getDirectoryRead(DirectoryList::MEDIA);
             $filePath = $path . '/' . $file;
             if ($dir->isFile($dir->getRelativePath($filePath))) {
                 $this->getStorage()->deleteFile($filePath);
             }
         }
         return $this->resultRawFactory->create();
     } catch (\Exception $e) {
         $result = ['error' => true, 'message' => $e->getMessage()];
         /** @var \Magento\Framework\Controller\Result\Json $resultJson */
         $resultJson = $this->resultJsonFactory->create();
         return $resultJson->setData($result);
     }
 }
 protected function setUp()
 {
     $this->productBuilder = $this->getMock('Magento\\Catalog\\Controller\\Adminhtml\\Product\\Builder', ['build'], [], '', false);
     $this->product = $this->getMockBuilder('Magento\\Catalog\\Model\\Product')->disableOriginalConstructor()->setMethods(['addData', 'getSku', 'getTypeId', 'getStoreId', '__sleep', '__wakeup', 'getAttributes', 'setAttributeSetId'])->getMock();
     $this->product->expects($this->any())->method('getTypeId')->will($this->returnValue('simple'));
     $this->product->expects($this->any())->method('getStoreId')->will($this->returnValue('1'));
     $this->product->expects($this->any())->method('getAttributes')->will($this->returnValue([]));
     $this->productBuilder->expects($this->any())->method('build')->will($this->returnValue($this->product));
     $this->resultPage = $this->getMockBuilder('Magento\\Backend\\Model\\View\\Result\\Page')->disableOriginalConstructor()->getMock();
     $resultPageFactory = $this->getMockBuilder('Magento\\Framework\\View\\Result\\PageFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock();
     $resultPageFactory->expects($this->any())->method('create')->willReturn($this->resultPage);
     $this->resultForward = $this->getMockBuilder('Magento\\Backend\\Model\\View\\Result\\Forward')->disableOriginalConstructor()->getMock();
     $resultForwardFactory = $this->getMockBuilder('Magento\\Backend\\Model\\View\\Result\\ForwardFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock();
     $resultForwardFactory->expects($this->any())->method('create')->willReturn($this->resultForward);
     $this->resultPage->expects($this->any())->method('getLayout')->willReturn($this->layout);
     $this->resultRedirectFactory = $this->getMock('Magento\\Backend\\Model\\View\\Result\\RedirectFactory', ['create'], [], '', false);
     $this->resultRedirect = $this->getMock('Magento\\Backend\\Model\\View\\Result\\Redirect', [], [], '', false);
     $this->resultRedirectFactory->expects($this->any())->method('create')->willReturn($this->resultRedirect);
     $this->initializationHelper = $this->getMock('Magento\\Catalog\\Controller\\Adminhtml\\Product\\Initialization\\Helper', [], [], '', false);
     $this->productFactory = $this->getMockBuilder('Magento\\Catalog\\Model\\ProductFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock();
     $this->productFactory->expects($this->any())->method('create')->willReturn($this->product);
     $this->resultJson = $this->getMock('Magento\\Framework\\Controller\\Result\\Json', [], [], '', false);
     $this->resultJsonFactory = $this->getMockBuilder('Magento\\Framework\\Controller\\Result\\JsonFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock();
     $this->resultJsonFactory->expects($this->any())->method('create')->willReturn($this->resultJson);
     $additionalParams = ['resultRedirectFactory' => $this->resultRedirectFactory];
     $this->action = (new ObjectManagerHelper($this))->getObject('Magento\\Catalog\\Controller\\Adminhtml\\Product\\Validate', ['context' => $this->initContext($additionalParams), 'productBuilder' => $this->productBuilder, 'resultPageFactory' => $resultPageFactory, 'resultForwardFactory' => $resultForwardFactory, 'initializationHelper' => $this->initializationHelper, 'resultJsonFactory' => $this->resultJsonFactory, 'productFactory' => $this->productFactory]);
 }
Esempio n. 6
0
 /**
  * @return \Magento\Framework\Controller\ResultInterface
  */
 public function execute()
 {
     /** @var \Magento\Framework\Controller\Result\Json $resultJson */
     $resultJson = $this->jsonFactory->create();
     $error = false;
     $messages = [];
     $postItems = $this->getRequest()->getParam('items', []);
     if (!($this->getRequest()->getParam('isAjax') && count($postItems))) {
         return $resultJson->setData(['messages' => [__('Please correct the data sent.')], 'error' => true]);
     }
     foreach (array_keys($postItems) as $groupId) {
         /** @var \Ves\Brand\Model\Group $group */
         $group = $this->_objectManager->create('Ves\\Brand\\Model\\Group');
         $groupData = $postItems[$groupId];
         try {
             $group->load($groupId);
             $group->setData(array_merge($group->getData(), $groupData));
             $group->save();
         } catch (\Magento\Framework\Exception\LocalizedException $e) {
             $messages[] = $this->getErrorWithgroupId($group, $e->getMessage());
             $error = true;
         } catch (\RuntimeException $e) {
             $messages[] = $this->getErrorWithgroupId($group, $e->getMessage());
             $error = true;
         } catch (\Exception $e) {
             $messages[] = $this->getErrorWithgroupId($group, __('URL key already exists.'));
             $error = true;
         }
     }
     return $resultJson->setData(['messages' => $messages, 'error' => $error]);
 }
Esempio n. 7
0
 /**
  * @return \Magento\Framework\Controller\ResultInterface
  */
 public function execute()
 {
     /** @var \Magento\Framework\Controller\Result\Json $resultJson */
     $resultJson = $this->jsonFactory->create();
     $error = false;
     $messages = [];
     $postItems = $this->getRequest()->getParam('items', []);
     if (!($this->getRequest()->getParam('isAjax') && count($postItems))) {
         return $resultJson->setData(['messages' => [__('Please correct the data sent.')], 'error' => true]);
     }
     foreach (array_keys($postItems) as $brandId) {
         /** @var \Ves\Brand\Model\Group $brand */
         $brand = $this->_objectManager->create('Ves\\Brand\\Model\\Brand');
         $brandData = $postItems[$brandId];
         try {
             $brand->load($brandId);
             $brand->setData(array_merge($brand->getData(), $brandData));
             $brand->save();
         } catch (\Magento\Framework\Exception\LocalizedException $e) {
             $messages[] = $this->getErrorWithgroupId($brand, $e->getMessage());
             $error = true;
         } catch (\RuntimeException $e) {
             $messages[] = $this->getErrorWithgroupId($brand, $e->getMessage());
             $error = true;
         } catch (\Exception $e) {
             $messages[] = $this->getErrorWithPageId($page, __('Something went wrong while saving the page.'));
             $error = true;
         }
     }
     return $resultJson->setData(['messages' => 'abc', 'error' => 'def']);
 }
Esempio n. 8
0
 /**
  * @return \Magento\Framework\Controller\ResultInterface
  */
 public function execute()
 {
     $response = new \Magento\Framework\Object();
     $response->setError(false);
     $attributeCode = $this->getRequest()->getParam('attribute_code');
     $frontendLabel = $this->getRequest()->getParam('frontend_label');
     $attributeCode = $attributeCode ?: $this->generateCode($frontendLabel[0]);
     $attributeId = $this->getRequest()->getParam('attribute_id');
     $attribute = $this->_objectManager->create('Magento\\Catalog\\Model\\Resource\\Eav\\Attribute')->loadByCode($this->_entityTypeId, $attributeCode);
     if ($attribute->getId() && !$attributeId) {
         if (strlen($this->getRequest()->getParam('attribute_code'))) {
             $response->setAttributes(['attribute_code' => __('An attribute with this code already exists.')]);
         } else {
             $response->setAttributes(['attribute_label' => __('Attribute with the same code (%1) already exists.', $attributeCode)]);
         }
         $response->setError(true);
     }
     if ($this->getRequest()->has('new_attribute_set_name')) {
         $setName = $this->getRequest()->getParam('new_attribute_set_name');
         /** @var $attributeSet \Magento\Eav\Model\Entity\Attribute\Set */
         $attributeSet = $this->_objectManager->create('Magento\\Eav\\Model\\Entity\\Attribute\\Set');
         $attributeSet->setEntityTypeId($this->_entityTypeId)->load($setName, 'attribute_set_name');
         if ($attributeSet->getId()) {
             $setName = $this->_objectManager->get('Magento\\Framework\\Escaper')->escapeHtml($setName);
             $this->messageManager->addError(__('Attribute Set with name \'%1\' already exists.', $setName));
             $layout = $this->layoutFactory->create();
             $layout->initMessages();
             $response->setError(true);
             $response->setHtmlMessage($layout->getMessagesBlock()->getGroupedHtml());
         }
     }
     return $this->resultJsonFactory->create()->setJsonData($response->toJson());
 }
Esempio n. 9
0
 /**
  * @param \Magento\Customer\Controller\Ajax\Login $subject
  * @param \Closure $proceed
  * @return $this
  * @throws \Zend_Json_Exception
  * @SuppressWarnings(PHPMD.NPathComplexity)
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 public function aroundExecute(\Magento\Customer\Controller\Ajax\Login $subject, \Closure $proceed)
 {
     $captchaFormIdField = 'captcha_form_id';
     $captchaInputName = 'captcha_string';
     /** @var \Magento\Framework\App\RequestInterface $request */
     $request = $subject->getRequest();
     $loginParams = [];
     $content = $request->getContent();
     if ($content) {
         $loginParams = \Zend_Json::decode($content);
     }
     $username = isset($loginParams['username']) ? $loginParams['username'] : null;
     $captchaString = isset($loginParams[$captchaInputName]) ? $loginParams[$captchaInputName] : null;
     $loginFormId = isset($loginParams[$captchaFormIdField]) ? $loginParams[$captchaFormIdField] : null;
     foreach ($this->formIds as $formId) {
         $captchaModel = $this->helper->getCaptcha($formId);
         if ($captchaModel->isRequired($username) && !in_array($loginFormId, $this->formIds)) {
             $resultJson = $this->resultJsonFactory->create();
             return $resultJson->setData(['errors' => true, 'message' => __('Provided form does not exist')]);
         }
         if ($formId == $loginFormId) {
             $captchaModel->logAttempt($username);
             if (!$captchaModel->isCorrect($captchaString)) {
                 $this->sessionManager->setUsername($username);
                 /** @var \Magento\Framework\Controller\Result\Json $resultJson */
                 $resultJson = $this->resultJsonFactory->create();
                 return $resultJson->setData(['errors' => true, 'message' => __('Incorrect CAPTCHA')]);
             }
         }
     }
     return $proceed();
 }
Esempio n. 10
0
 /**
  * Attributes validation action
  *
  * @return \Magento\Framework\Controller\ResultInterface
  */
 public function executeInternal()
 {
     $response = $this->_objectManager->create('Magento\\Framework\\DataObject');
     $response->setError(false);
     $attributesData = $this->getRequest()->getParam('attributes', []);
     $data = $this->_objectManager->create('Magento\\Catalog\\Model\\Product');
     try {
         if ($attributesData) {
             foreach ($attributesData as $attributeCode => $value) {
                 $attribute = $this->_objectManager->get('Magento\\Eav\\Model\\Config')->getAttribute('catalog_product', $attributeCode);
                 if (!$attribute->getAttributeId()) {
                     unset($attributesData[$attributeCode]);
                     continue;
                 }
                 $data->setData($attributeCode, $value);
                 $attribute->getBackend()->validate($data);
             }
         }
     } catch (\Magento\Eav\Model\Entity\Attribute\Exception $e) {
         $response->setError(true);
         $response->setAttribute($e->getAttributeCode());
         $response->setMessage($e->getMessage());
     } catch (\Magento\Framework\Exception\LocalizedException $e) {
         $response->setError(true);
         $response->setMessage($e->getMessage());
     } catch (\Exception $e) {
         $this->messageManager->addException($e, __('Something went wrong while updating the product(s) attributes.'));
         $layout = $this->layoutFactory->create();
         $layout->initMessages();
         $response->setError(true);
         $response->setHtmlMessage($layout->getMessagesBlock()->getGroupedHtml());
     }
     return $this->resultJsonFactory->create()->setJsonData($response->toJson());
 }
Esempio n. 11
0
 public function setUp()
 {
     if (!function_exists('libxml_set_external_entity_loader')) {
         $this->markTestSkipped('Skipped on HHVM. Will be fixed in MAGETWO-45033');
     }
     $this->customer = $this->getMockForAbstractClass('Magento\\Customer\\Api\\Data\\CustomerInterface', [], '', false, true, true);
     $this->customer->expects($this->once())->method('getWebsiteId')->willReturn(2);
     $this->customerDataFactory = $this->getMock('Magento\\Customer\\Api\\Data\\CustomerInterfaceFactory', ['create'], [], '', false);
     $this->customerDataFactory->expects($this->once())->method('create')->willReturn($this->customer);
     $this->form = $this->getMock('Magento\\Customer\\Model\\Metadata\\Form', [], [], '', false);
     $this->request = $this->getMockForAbstractClass('Magento\\Framework\\App\\RequestInterface', [], '', false, true, true, ['getPost']);
     $this->response = $this->getMockForAbstractClass('Magento\\Framework\\App\\ResponseInterface', [], '', false);
     $this->formFactory = $this->getMock('Magento\\Customer\\Model\\Metadata\\FormFactory', ['create'], [], '', false);
     $this->formFactory->expects($this->atLeastOnce())->method('create')->willReturn($this->form);
     $this->extensibleDataObjectConverter = $this->getMock('Magento\\Framework\\Api\\ExtensibleDataObjectConverter', [], [], '', false);
     $this->dataObjectHelper = $this->getMock('Magento\\Framework\\Api\\DataObjectHelper', [], [], '', false);
     $this->dataObjectHelper->expects($this->once())->method('populateWithArray');
     $this->customerAccountManagement = $this->getMockForAbstractClass('Magento\\Customer\\Api\\AccountManagementInterface', [], '', false, true, true);
     $this->resultJson = $this->getMock('Magento\\Framework\\Controller\\Result\\Json', [], [], '', false);
     $this->resultJson->expects($this->once())->method('setData');
     $this->resultJsonFactory = $this->getMock('Magento\\Framework\\Controller\\Result\\JsonFactory', ['create'], [], '', false);
     $this->resultJsonFactory->expects($this->once())->method('create')->willReturn($this->resultJson);
     $objectHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
     $this->controller = $objectHelper->getObject('Magento\\Customer\\Controller\\Adminhtml\\Index\\Validate', ['request' => $this->request, 'response' => $this->response, 'customerDataFactory' => $this->customerDataFactory, 'formFactory' => $this->formFactory, 'extensibleDataObjectConverter' => $this->extensibleDataObjectConverter, 'customerAccountManagement' => $this->customerAccountManagement, 'resultJsonFactory' => $this->resultJsonFactory, 'dataObjectHelper' => $this->dataObjectHelper]);
 }
 /**
  * @return \Magento\Framework\Controller\ResultInterface
  */
 public function execute()
 {
     /** @var \Magento\Framework\Controller\Result\Json $resultJson */
     $resultJson = $this->jsonFactory->create();
     $error = false;
     $messages = [];
     $postItems = $this->getRequest()->getParam('items', []);
     if (!($this->getRequest()->getParam('isAjax') && count($postItems))) {
         return $resultJson->setData(['messages' => [__('Please correct the data sent.')], 'error' => true]);
     }
     foreach (array_keys($postItems) as $tagId) {
         /** @var \Mageplaza\Blog\Model\Tag $tag */
         $tag = $this->tagFactory->create()->load($tagId);
         try {
             $tagData = $postItems[$tagId];
             //todo: handle dates
             $tag->addData($tagData);
             $tag->save();
         } catch (\Magento\Framework\Exception\LocalizedException $e) {
             $messages[] = $this->getErrorWithTagId($tag, $e->getMessage());
             $error = true;
         } catch (\RuntimeException $e) {
             $messages[] = $this->getErrorWithTagId($tag, $e->getMessage());
             $error = true;
         } catch (\Exception $e) {
             $messages[] = $this->getErrorWithTagId($tag, __('Something went wrong while saving the Tag.'));
             $error = true;
         }
     }
     return $resultJson->setData(['messages' => $messages, 'error' => $error]);
 }
Esempio n. 13
0
 /**
  * @return \Magento\Framework\Controller\ResultInterface
  */
 public function execute()
 {
     /** @var \Magento\Framework\Controller\Result\Json $resultJson */
     $resultJson = $this->jsonFactory->create();
     $error = false;
     $messages = [];
     if ($this->getRequest()->getParam('isAjax')) {
         $postItems = $this->getRequest()->getParam('items', []);
         if (!count($postItems)) {
             $messages[] = __('Please correct the data sent.');
             $error = true;
         } else {
             foreach (array_keys($postItems) as $blockId) {
                 /** @var \Magento\Cms\Model\Block $block */
                 $block = $this->blockRepository->getById($blockId);
                 try {
                     $block->setData(array_merge($block->getData(), $postItems[$blockId]));
                     $this->blockRepository->save($block);
                 } catch (\Exception $e) {
                     $messages[] = $e->getMessage();
                     // $this->getErrorWithBlockId(
                     //     $block,
                     //     __($e->getMessage())
                     // );
                     $error = true;
                 }
             }
         }
     }
     return $resultJson->setData(['messages' => $messages, 'error' => $error]);
 }
 /**
  * Add comment to creditmemo history
  *
  * @return \Magento\Framework\Controller\Result\Raw|\Magento\Framework\Controller\Result\Json
  */
 public function execute()
 {
     try {
         $this->getRequest()->setParam('creditmemo_id', $this->getRequest()->getParam('id'));
         $data = $this->getRequest()->getPost('comment');
         if (empty($data['comment'])) {
             throw new \Magento\Framework\Exception\LocalizedException(__('Please enter a comment.'));
         }
         $this->creditmemoLoader->setOrderId($this->getRequest()->getParam('order_id'));
         $this->creditmemoLoader->setCreditmemoId($this->getRequest()->getParam('creditmemo_id'));
         $this->creditmemoLoader->setCreditmemo($this->getRequest()->getParam('creditmemo'));
         $this->creditmemoLoader->setInvoiceId($this->getRequest()->getParam('invoice_id'));
         $creditmemo = $this->creditmemoLoader->load();
         $comment = $creditmemo->addComment($data['comment'], isset($data['is_customer_notified']), isset($data['is_visible_on_front']));
         $comment->save();
         $this->creditmemoCommentSender->send($creditmemo, !empty($data['is_customer_notified']), $data['comment']);
         $resultPage = $this->resultPageFactory->create();
         $response = $resultPage->getLayout()->getBlock('creditmemo_comments')->toHtml();
     } catch (\Magento\Framework\Exception\LocalizedException $e) {
         $response = ['error' => true, 'message' => $e->getMessage()];
     } catch (\Exception $e) {
         $response = ['error' => true, 'message' => __('Cannot add new comment.')];
     }
     if (is_array($response)) {
         $resultJson = $this->resultJsonFactory->create();
         $resultJson->setData($response);
         return $resultJson;
     } else {
         $resultRaw = $this->resultRawFactory->create();
         $resultRaw->setContents($response);
         return $resultRaw;
     }
 }
 /**
  * Add attribute to attribute set
  *
  * @return \Magento\Framework\Controller\Result\Json
  */
 public function execute()
 {
     $request = $this->getRequest();
     $resultJson = $this->resultJsonFactory->create();
     try {
         /** @var \Magento\Eav\Model\Entity\Attribute $attribute */
         $attribute = $this->_objectManager->create('Magento\\Eav\\Model\\Entity\\Attribute')->load($request->getParam('attribute_id'));
         $attributeSet = $this->_objectManager->create('Magento\\Eav\\Model\\Entity\\Attribute\\Set')->load($request->getParam('template_id'));
         /** @var \Magento\Eav\Model\ResourceModel\Entity\Attribute\Group\Collection $attributeGroupCollection */
         $attributeGroupCollection = $this->_objectManager->get('Magento\\Eav\\Model\\ResourceModel\\Entity\\Attribute\\Group\\Collection');
         $attributeGroupCollection->setAttributeSetFilter($attributeSet->getId());
         $attributeGroupCollection->addFilter('attribute_group_code', $request->getParam('group'));
         $attributeGroupCollection->setPageSize(1);
         $attributeGroup = $attributeGroupCollection->getFirstItem();
         $attribute->setAttributeSetId($attributeSet->getId())->loadEntityAttributeIdBySet();
         $attribute->setAttributeSetId($request->getParam('template_id'))->setAttributeGroupId($attributeGroup->getId())->setSortOrder('0')->save();
         $resultJson->setJsonData($attribute->toJson());
     } catch (\Exception $e) {
         $response = new \Magento\Framework\DataObject();
         $response->setError(false);
         $response->setMessage($e->getMessage());
         $resultJson->setJsonData($response->toJson());
     }
     return $resultJson;
 }
Esempio n. 16
0
 /**
  * Check whether vat is valid
  *
  * @return \Magento\Framework\Controller\Result\Json
  */
 public function execute()
 {
     $result = $this->_validate();
     /** @var \Magento\Framework\Controller\Result\Json $resultJson */
     $resultJson = $this->resultJsonFactory->create();
     return $resultJson->setData(['valid' => (int) $result->getIsValid(), 'message' => $result->getRequestMessage()]);
 }
Esempio n. 17
0
 /**
  * Update items qty action
  *
  * @return \Magento\Framework\Controller\Result\Json|\Magento\Framework\Controller\Result\Raw
  */
 public function executeInternal()
 {
     try {
         $this->creditmemoLoader->setOrderId($this->getRequest()->getParam('order_id'));
         $this->creditmemoLoader->setCreditmemoId($this->getRequest()->getParam('creditmemo_id'));
         $this->creditmemoLoader->setCreditmemo($this->getRequest()->getParam('creditmemo'));
         $this->creditmemoLoader->setInvoiceId($this->getRequest()->getParam('invoice_id'));
         $this->creditmemoLoader->load();
         $resultPage = $this->resultPageFactory->create();
         $response = $resultPage->getLayout()->getBlock('order_items')->toHtml();
     } catch (\Magento\Framework\Exception\LocalizedException $e) {
         $response = ['error' => true, 'message' => $e->getMessage()];
     } catch (\Exception $e) {
         $response = ['error' => true, 'message' => __('We can\'t update the item\'s quantity right now.')];
     }
     if (is_array($response)) {
         $resultJson = $this->resultJsonFactory->create();
         $resultJson->setData($response);
         return $resultJson;
     } else {
         $resultRaw = $this->resultRawFactory->create();
         $resultRaw->setContents($response);
         return $resultRaw;
     }
 }
Esempio n. 18
0
 /**
  * @return \Magento\Framework\Controller\ResultInterface
  */
 public function execute()
 {
     /** @var \Magento\Framework\Controller\Result\Json $resultJson */
     $resultJson = $this->jsonFactory->create();
     $error = false;
     $messages = [];
     $postItems = $this->getRequest()->getParam('items', []);
     if (!($this->getRequest()->getParam('isAjax') && count($postItems))) {
         return $resultJson->setData(['messages' => [__('Please correct the data sent.')], 'error' => true]);
     }
     foreach (array_keys($postItems) as $pageId) {
         /** @var \Magento\Cms\Model\Page $page */
         $page = $this->pageRepository->getById($pageId);
         try {
             $pageData = $this->filterPost($postItems[$pageId]);
             $this->validatePost($pageData, $page, $error, $messages);
             $extendedPageData = $page->getData();
             $this->setCmsPageData($page, $extendedPageData, $pageData);
             $this->pageRepository->save($page);
         } catch (\Magento\Framework\Exception\LocalizedException $e) {
             $messages[] = $this->getErrorWithPageId($page, $e->getMessage());
             $error = true;
         } catch (\RuntimeException $e) {
             $messages[] = $this->getErrorWithPageId($page, $e->getMessage());
             $error = true;
         } catch (\Exception $e) {
             $messages[] = $this->getErrorWithPageId($page, __('Something went wrong while saving the page.'));
             $error = true;
         }
     }
     return $resultJson->setData(['messages' => $messages, 'error' => $error]);
 }
Esempio n. 19
0
 /**
  * Customer logout action
  *
  * @return \Magento\Framework\Controller\Result\Json
  */
 public function execute()
 {
     $lastCustomerId = $this->customerSession->getId();
     $this->customerSession->logout()->setBeforeAuthUrl($this->_redirect->getRefererUrl())->setLastCustomerId($lastCustomerId);
     /** @var \Magento\Framework\Controller\Result\Json $resultJson */
     $resultJson = $this->resultJsonFactory->create();
     return $resultJson->setData(['message' => 'Logout Successful']);
 }
Esempio n. 20
0
 /**
  * AJAX category validation action
  *
  * @return \Magento\Framework\Controller\Result\Json
  */
 public function execute()
 {
     $response = new \Magento\Framework\DataObject();
     $response->setError(0);
     $resultJson = $this->resultJsonFactory->create();
     $resultJson->setData($response);
     return $resultJson;
 }
Esempio n. 21
0
 public function testExecuteWithoutData()
 {
     $this->request->expects($this->at(0))->method('getParam')->with('isAjax')->willReturn(true);
     $this->request->expects($this->at(1))->method('getParam')->with('items', [])->willReturn([]);
     $this->jsonFactory->expects($this->once())->method('create')->willReturn($this->resultJson);
     $this->resultJson->expects($this->once())->method('setData')->with(['messages' => ['Please correct the data sent.'], 'error' => true])->willReturnSelf();
     $this->controller->execute();
 }
Esempio n. 22
0
 /**
  * Retrieve synchronize process state and it's parameters in json format
  *
  * @return \Magento\Framework\Controller\Result\Json
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 public function execute()
 {
     $result = [];
     $flag = $this->_getSyncFlag();
     if ($flag) {
         $state = $flag->getState();
         switch ($state) {
             case \Magento\MediaStorage\Model\File\Storage\Flag::STATE_INACTIVE:
                 $flagData = $flag->getFlagData();
                 if (is_array($flagData)) {
                     if (isset($flagData['destination']) && !empty($flagData['destination'])) {
                         $result['destination'] = $flagData['destination'];
                     }
                 }
                 $state = \Magento\MediaStorage\Model\File\Storage\Flag::STATE_INACTIVE;
                 break;
             case \Magento\MediaStorage\Model\File\Storage\Flag::STATE_RUNNING:
                 if (!$flag->getLastUpdate() || time() <= strtotime($flag->getLastUpdate()) + \Magento\MediaStorage\Model\File\Storage\Flag::FLAG_TTL) {
                     $flagData = $flag->getFlagData();
                     if (is_array($flagData) && isset($flagData['source']) && !empty($flagData['source']) && isset($flagData['destination']) && !empty($flagData['destination'])) {
                         $result['message'] = __('Synchronizing %1 to %2', $flagData['source'], $flagData['destination']);
                     } else {
                         $result['message'] = __('Synchronizing...');
                     }
                     break;
                 } else {
                     $flagData = $flag->getFlagData();
                     if (is_array($flagData) && !(isset($flagData['timeout_reached']) && $flagData['timeout_reached'])) {
                         $this->_objectManager->get('Psr\\Log\\LoggerInterface')->critical(new \Magento\Framework\Exception(__('The timeout limit for response from synchronize process was reached.')));
                         $state = \Magento\MediaStorage\Model\File\Storage\Flag::STATE_FINISHED;
                         $flagData['has_errors'] = true;
                         $flagData['timeout_reached'] = true;
                         $flag->setState($state)->setFlagData($flagData)->save();
                     }
                 }
                 // fall-through intentional
             // fall-through intentional
             case \Magento\MediaStorage\Model\File\Storage\Flag::STATE_FINISHED:
             case \Magento\MediaStorage\Model\File\Storage\Flag::STATE_NOTIFIED:
                 $flagData = $flag->getFlagData();
                 if (!isset($flagData['has_errors'])) {
                     $flagData['has_errors'] = false;
                 }
                 $result['has_errors'] = $flagData['has_errors'];
                 break;
             default:
                 $state = \Magento\MediaStorage\Model\File\Storage\Flag::STATE_INACTIVE;
                 break;
         }
     } else {
         $state = \Magento\MediaStorage\Model\File\Storage\Flag::STATE_INACTIVE;
     }
     $result['state'] = $state;
     /** @var \Magento\Framework\Controller\Result\Json $resultJson */
     $resultJson = $this->resultJsonFactory->create();
     return $resultJson->setData($result);
 }
Esempio n. 23
0
 /**
  * @param bool $result
  * @dataProvider dataProviderTestExecute
  */
 public function testExecute($result)
 {
     $resultExpectation = ['isActive' => $result];
     $jsonMock = $this->getMockBuilder('Magento\\Framework\\Controller\\Result\\Json')->disableOriginalConstructor()->getMock();
     $this->sessionsManager->expects($this->any())->method('getCurrentSession')->willReturn($this->currentSession);
     $this->currentSession->expects($this->any())->method('isActive')->will($this->returnValue($result));
     $this->jsonFactory->expects($this->any())->method('create')->willReturn($jsonMock);
     $jsonMock->expects($this->once())->method('setData')->with($resultExpectation)->willReturnSelf();
     $this->assertEquals($jsonMock, $this->controller->execute());
 }
Esempio n. 24
0
 /**
  * Build response for refresh input element 'path' in form
  *
  * @return \Magento\Framework\Controller\Result\Json
  */
 public function executeInternal()
 {
     $categoryId = (int) $this->getRequest()->getParam('id');
     if ($categoryId) {
         $category = $this->_objectManager->create('Magento\\Catalog\\Model\\Category')->load($categoryId);
         /** @var \Magento\Framework\Controller\Result\Json $resultJson */
         $resultJson = $this->resultJsonFactory->create();
         return $resultJson->setData(['id' => $categoryId, 'path' => $category->getPath()]);
     }
 }
 /**
  * Build response for refresh input element 'path' in form
  *
  * @return \Magento\Framework\Controller\Result\Json
  */
 public function execute()
 {
     $categoryId = (int) $this->getRequest()->getParam('category_id');
     if ($categoryId) {
         $category = $this->categoryFactory->create()->load($categoryId);
         /** @var \Magento\Framework\Controller\Result\Json $resultJson */
         $resultJson = $this->resultJsonFactory->create();
         return $resultJson->setData(['id' => $categoryId, 'path' => $category->getPath()]);
     }
 }
Esempio n. 26
0
 /**
  * Delete folder action
  *
  * @return \Magento\Framework\Controller\ResultInterface
  */
 public function execute()
 {
     try {
         $path = $this->getStorage()->getCmsWysiwygImages()->getCurrentPath();
         $this->getStorage()->deleteDirectory($path);
         return $this->resultRawFactory->create();
     } catch (\Exception $e) {
         $result = ['error' => true, 'message' => $e->getMessage()];
         /** @var \Magento\Framework\Controller\Result\Json $resultJson */
         $resultJson = $this->resultJsonFactory->create();
         return $resultJson->setData($result);
     }
 }
Esempio n. 27
0
 public function testExecute()
 {
     $this->requestMock->expects($this->any())->method('getParam')->willReturnMap([['frontend_label', null, 'test_frontend_label'], ['attribute_code', null, 'test_attribute_code'], ['new_attribute_set_name', null, 'test_attribute_set_name']]);
     $this->objectManagerMock->expects($this->exactly(2))->method('create')->willReturnMap([['Magento\\Catalog\\Model\\ResourceModel\\Eav\\Attribute', [], $this->attributeMock], ['Magento\\Eav\\Model\\Entity\\Attribute\\Set', [], $this->attributeSetMock]]);
     $this->attributeMock->expects($this->once())->method('loadByCode')->willReturnSelf();
     $this->requestMock->expects($this->once())->method('has')->with('new_attribute_set_name')->willReturn(true);
     $this->attributeSetMock->expects($this->once())->method('setEntityTypeId')->willReturnSelf();
     $this->attributeSetMock->expects($this->once())->method('load')->willReturnSelf();
     $this->attributeSetMock->expects($this->once())->method('getId')->willReturn(false);
     $this->resultJsonFactoryMock->expects($this->once())->method('create')->willReturn($this->resultJson);
     $this->resultJson->expects($this->once())->method('setJsonData')->willReturnSelf();
     $this->assertInstanceOf(ResultJson::class, $this->getModel()->execute());
 }
 /**
  * @return $this
  */
 public function execute()
 {
     $result = $this->_resultJsonFactory->create();
     $productId = $this->getRequest()->getParam('id');
     if (empty($productId)) {
         return $result->setData(['error' => true, 'message' => 'Product ID has not been supplied']);
     }
     $pageViewResult = $this->_productView->processViews($productId);
     if (!$pageViewResult) {
         return $result->setData(['error' => true, 'message' => 'There was an error processing the product view.']);
     }
     return $result->setData(['success' => true, 'message' => 'Product view logged in PredictionIO']);
 }
Esempio n. 29
0
 /**
  * Send request to PayfloPro gateway for get Secure Token
  *
  * @return ResultInterface
  */
 public function execute()
 {
     $this->sessionTransparent->setQuoteId($this->sessionManager->getQuote()->getId());
     $token = $this->secureTokenService->requestToken($this->sessionManager->getQuote());
     $result = [];
     $result[$this->transparent->getCode()]['fields'] = $token->getData();
     $result['success'] = $token->getSecuretoken() ? true : false;
     if (!$result['success']) {
         $result['error'] = true;
         $result['error_messages'] = __('Secure Token Error. Try again.');
     }
     return $this->resultJsonFactory->create()->setData($result);
 }
Esempio n. 30
0
 /**
  * Files upload processing
  *
  * @return \Magento\Framework\Controller\ResultInterface
  */
 public function execute()
 {
     try {
         $this->_initAction();
         $targetPath = $this->getStorage()->getSession()->getCurrentPath();
         $result = $this->getStorage()->uploadFile($targetPath, $this->getRequest()->getParam('type'));
     } catch (\Exception $e) {
         $result = ['error' => $e->getMessage(), 'errorcode' => $e->getCode()];
     }
     /** @var \Magento\Framework\Controller\Result\Json $resultJson */
     $resultJson = $this->resultJsonFactory->create();
     return $resultJson->setData($result);
 }