/** * Forward request for a graph image to the web-service * * This is done in order to include the image to a HTTPS-page regardless of web-service settings * * @return \Magento\Framework\Controller\Result\Raw */ public function execute() { $error = __('invalid request'); $httpCode = 400; $gaData = $this->_request->getParam('ga'); $gaHash = $this->_request->getParam('h'); /** @var \Magento\Framework\Controller\Result\Raw $resultRaw */ $resultRaw = $this->resultRawFactory->create(); if ($gaData && $gaHash) { /** @var $helper \Magento\Backend\Helper\Dashboard\Data */ $helper = $this->_objectManager->get('Magento\\Backend\\Helper\\Dashboard\\Data'); $newHash = $helper->getChartDataHash($gaData); if ($newHash == $gaHash) { $params = json_decode(base64_decode(urldecode($gaData)), true); if ($params) { try { /** @var $httpClient \Magento\Framework\HTTP\ZendClient */ $httpClient = $this->_objectManager->create('Magento\\Framework\\HTTP\\ZendClient'); $response = $httpClient->setUri(\Magento\Backend\Block\Dashboard\Graph::API_URL)->setParameterGet($params)->setConfig(['timeout' => 5])->request('GET'); $headers = $response->getHeaders(); $resultRaw->setHeader('Content-type', $headers['Content-type'])->setContents($response->getBody()); return $resultRaw; } catch (\Exception $e) { $this->_objectManager->get('Psr\\Log\\LoggerInterface')->critical($e); $error = __('see error log for details'); $httpCode = 503; } } } } $resultRaw->setHeader('Content-Type', 'text/plain; charset=UTF-8')->setHttpResponseCode($httpCode)->setContents(__('Service unavailable: %1', $error)); return $resultRaw; }
/** * @return \Magento\Framework\Controller\Result\Raw */ public function execute() { try { $uploader = $this->_objectManager->create('Magento\\MediaStorage\\Model\\File\\Uploader', ['fileId' => 'image']); $uploader->setAllowedExtensions(['jpg', 'jpeg', 'gif', 'png']); /** @var \Magento\Framework\Image\Adapter\AdapterInterface $imageAdapter */ $imageAdapter = $this->_objectManager->get('Magento\\Framework\\Image\\AdapterFactory')->create(); $uploader->addValidateCallback('catalog_product_image', $imageAdapter, 'validateUploadFile'); $uploader->setAllowRenameFiles(true); $uploader->setFilesDispersion(true); /** @var \Magento\Framework\Filesystem\Directory\Read $mediaDirectory */ $mediaDirectory = $this->_objectManager->get('Magento\\Framework\\Filesystem')->getDirectoryRead(DirectoryList::MEDIA); $config = $this->_objectManager->get('Magento\\Catalog\\Model\\Product\\Media\\Config'); $result = $uploader->save($mediaDirectory->getAbsolutePath($config->getBaseTmpMediaPath())); $this->_eventManager->dispatch('catalog_product_gallery_upload_image_after', ['result' => $result, 'action' => $this]); unset($result['tmp_name']); unset($result['path']); $result['url'] = $this->_objectManager->get('Magento\\Catalog\\Model\\Product\\Media\\Config')->getTmpMediaUrl($result['file']); $result['file'] = $result['file'] . '.tmp'; } catch (\Exception $e) { $result = ['error' => $e->getMessage(), 'errorcode' => $e->getCode()]; } /** @var \Magento\Framework\Controller\Result\Raw $response */ $response = $this->resultRawFactory->create(); $response->setHeader('Content-type', 'text/plain'); $response->setContents(json_encode($result)); return $response; }
/** * Login registered users and initiate a session. * * Expects a POST. ex for JSON {"username":"******", "password":"******"} * * @return \Magento\Framework\Controller\ResultInterface */ public function execute() { $credentials = null; $httpBadRequestCode = 400; /** @var \Magento\Framework\Controller\Result\Raw $resultRaw */ $resultRaw = $this->resultRawFactory->create(); try { $credentials = $this->helper->jsonDecode($this->getRequest()->getContent()); } catch (\Exception $e) { return $resultRaw->setHttpResponseCode($httpBadRequestCode); } if (!$credentials || $this->getRequest()->getMethod() !== 'POST' || !$this->getRequest()->isXmlHttpRequest()) { return $resultRaw->setHttpResponseCode($httpBadRequestCode); } $response = ['errors' => false, 'message' => __('Login successful.')]; try { $customer = $this->customerAccountManagement->authenticate($credentials['username'], $credentials['password']); $this->customerSession->setCustomerDataAsLoggedIn($customer); $this->customerSession->regenerateId(); } catch (EmailNotConfirmedException $e) { $response = ['errors' => true, 'message' => $e->getMessage()]; } catch (InvalidEmailOrPasswordException $e) { $response = ['errors' => true, 'message' => $e->getMessage()]; } catch (\Exception $e) { $response = ['errors' => true, 'message' => __('Something went wrong while validating the login and password.')]; } /** @var \Magento\Framework\Controller\Result\Json $resultJson */ $resultJson = $this->resultJsonFactory->create(); return $resultJson->setData($response); }
/** * Check whether vat is valid * * @return \Magento\Framework\Controller\Result\Raw */ public function execute() { $result = $this->_validate(); /** @var \Magento\Framework\Controller\Result\Raw $resultRaw */ $resultRaw = $this->resultRawFactory->create(); return $resultRaw->setContents((int) $result->getIsValid()); }
/** * 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); } }
/** * 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; } }
/** * Get specified tab grid * * @return \Magento\Framework\Controller\Result\Raw */ public function execute() { $this->_view->getPage()->getConfig()->getTitle()->prepend(__('Products')); $this->productBuilder->build($this->getRequest()); $block = $this->getRequest()->getParam('gridOnlyBlock'); $blockClassSuffix = str_replace(' ', '_', ucwords(str_replace('_', ' ', $block))); /** @var \Magento\Framework\Controller\Result\Raw $resultRaw */ $resultRaw = $this->resultRawFactory->create(); return $resultRaw->setContents($this->layoutFactory->create()->createBlock('Magento\\Catalog\\Block\\Adminhtml\\Product\\Edit\\Tab\\' . $blockClassSuffix)->toHtml()); }
/** * WYSIWYG editor action for ajax request * * @return \Magento\Framework\Controller\Result\Raw */ public function execute() { $elementId = $this->getRequest()->getParam('element_id', md5(microtime())); $storeId = $this->getRequest()->getParam('store_id', 0); $storeMediaUrl = $this->_objectManager->get('Magento\\Store\\Model\\StoreManagerInterface')->getStore($storeId)->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA); $content = $this->layoutFactory->create()->createBlock('Magento\\Catalog\\Block\\Adminhtml\\Helper\\Form\\Wysiwyg\\Content', '', ['data' => ['editor_element_id' => $elementId, 'store_id' => $storeId, 'store_media_url' => $storeMediaUrl]]); /** @var \Magento\Framework\Controller\Result\Raw $resultRaw */ $resultRaw = $this->resultRawFactory->create(); return $resultRaw->setContents($content->toHtml()); }
/** * Save fieldset state through AJAX * * @return \Magento\Framework\Controller\Result\Raw */ public function execute() { if ($this->getRequest()->getParam('isAjax') && $this->getRequest()->getParam('container') != '' && $this->getRequest()->getParam('value') != '') { $configState = [$this->getRequest()->getParam('container') => $this->getRequest()->getParam('value')]; $this->_saveState($configState); /** @var \Magento\Framework\Controller\Result\Raw $resultRaw */ $resultRaw = $this->resultRawFactory->create(); return $resultRaw->setContents('success'); } }
/** * Chooser Source action * * @return \Magento\Framework\Controller\Result\Raw */ public function execute() { $uniqId = $this->getRequest()->getParam('uniq_id'); /** @var \Magento\Framework\View\Layout $layout */ $layout = $this->layoutFactory->create(); $pagesGrid = $layout->createBlock('Magento\\Cms\\Block\\Adminhtml\\Page\\Widget\\Chooser', '', ['data' => ['id' => $uniqId]]); $html = $pagesGrid->toHtml(); /** @var \Magento\Framework\Controller\Result\Raw $resultRaw */ $resultRaw = $this->resultRawFactory->create(); return $resultRaw->setContents($html); }
/** * Show item update result from loadBlockAction * to prevent popup alert with resend data question * * @return \Magento\Framework\Controller\Result\Raw */ public function execute() { /** @var \Magento\Framework\Controller\Result\Raw $resultRaw */ $resultRaw = $this->resultRawFactory->create(); $session = $this->_objectManager->get('Magento\\Backend\\Model\\Session'); if ($session->hasUpdateResult() && is_scalar($session->getUpdateResult())) { $resultRaw->setContents($session->getUpdateResult()); } $session->unsUpdateResult(); return $resultRaw; }
/** * Grid Action * Display list of products related to current category * * @return \Magento\Framework\Controller\Result\Raw */ public function execute() { $category = $this->_initCategory(true); if (!$category) { /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ $resultRedirect = $this->resultRedirectFactory->create(); return $resultRedirect->setPath('catalog/*/', ['_current' => true, 'id' => null]); } /** @var \Magento\Framework\Controller\Result\Raw $resultRaw */ $resultRaw = $this->resultRawFactory->create(); return $resultRaw->setContents($this->layoutFactory->create()->createBlock('Magento\\Catalog\\Block\\Adminhtml\\Category\\Tab\\Product', 'category.product.grid')->toHtml()); }
/** * @return \Magento\Framework\Controller\Result\Raw */ public function execute() { $output = ''; $blockTab = $this->getRequest()->getParam('block'); $blockClassSuffix = str_replace(' ', '\\', ucwords(str_replace('_', ' ', $blockTab))); if (in_array($blockTab, ['tab_orders', 'tab_amounts', 'totals'])) { $output = $this->layoutFactory->create()->createBlock('Magento\\Backend\\Block\\Dashboard\\' . $blockClassSuffix)->toHtml(); } /** @var \Magento\Framework\Controller\Result\Raw $resultRaw */ $resultRaw = $this->resultRawFactory->create(); return $resultRaw->setContents($output); }
/** * 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); } }
/** * Fire when select image * * @return \Magento\Framework\Controller\ResultInterface */ public function execute() { $helper = $this->_objectManager->get('Magento\\Cms\\Helper\\Wysiwyg\\Images'); $storeId = $this->getRequest()->getParam('store'); $filename = $this->getRequest()->getParam('filename'); $filename = $helper->idDecode($filename); $asIs = $this->getRequest()->getParam('as_is'); $this->_objectManager->get('Magento\\Catalog\\Helper\\Data')->setStoreId($storeId); $helper->setStoreId($storeId); $image = $helper->getImageHtmlDeclaration($filename, $asIs); /** @var \Magento\Framework\Controller\Result\Raw $resultRaw */ $resultRaw = $this->resultRawFactory->create(); return $resultRaw->setContents($image); }
/** * @return \Magento\Backend\Model\View\Result\Redirect */ public function execute() { /** @var \Magento\Framework\Module\Dir\Reader $reader */ $reader = $this->_objectManager->get('Magento\\Framework\\Module\\Dir\\Reader'); $viewDir = $reader->getModuleDir(\Magento\Framework\Module\Dir::MODULE_VIEW_DIR, 'Owebia_AdvancedShippingSetting'); $locale = $this->_localeResolver->getLocale(); $defaultPath = $viewDir . '/doc_en_US.html'; $localePath = str_replace('en_US', $locale, $defaultPath); /** @var Filesystem $filesystem */ $filesystem = $this->_objectManager->get('Magento\\Framework\\Filesystem'); $readInterface = $filesystem->getDirectoryRead(DirectoryList::ROOT); $docPath = $readInterface->isFile($localePath) ? $localePath : $defaultPath; $docRelativePath = $readInterface->getRelativePath($docPath); return $this->resultRawFactory->create()->setHttpResponseCode(200)->setHeader('Pragma', 'public', true)->setHeader('Content-type', 'text/html; charset=UTF-8', true)->setContents($readInterface->readFile($docRelativePath)); }
/** * Login registered users and initiate a session. * * Expects a POST. ex for JSON {"username":"******", "password":"******"} * * @return \Magento\Framework\Controller\ResultInterface * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ public function execute() { $credentials = null; $httpBadRequestCode = 400; /** @var \Magento\Framework\Controller\Result\Raw $resultRaw */ $resultRaw = $this->resultRawFactory->create(); try { $credentials = $this->helper->jsonDecode($this->getRequest()->getContent()); } catch (\Exception $e) { return $resultRaw->setHttpResponseCode($httpBadRequestCode); } if (!$credentials || $this->getRequest()->getMethod() !== 'POST' || !$this->getRequest()->isXmlHttpRequest()) { return $resultRaw->setHttpResponseCode($httpBadRequestCode); } $response = ['errors' => false, 'message' => __('Login successful.')]; try { $customer = $this->customerAccountManagement->authenticate($credentials['username'], $credentials['password']); $this->customerSession->setCustomerDataAsLoggedIn($customer); $this->customerSession->regenerateId(); $redirectRoute = $this->getAccountRedirect()->getRedirectCookie(); if (!$this->getScopeConfig()->getValue('customer/startup/redirect_dashboard') && $redirectRoute) { $response['redirectUrl'] = $this->_redirect->success($redirectRoute); $this->getAccountRedirect()->clearRedirectCookie(); } } catch (EmailNotConfirmedException $e) { $response = ['errors' => true, 'message' => $e->getMessage()]; } catch (InvalidEmailOrPasswordException $e) { $response = ['errors' => true, 'message' => $e->getMessage()]; } catch (\Exception $e) { $response = ['errors' => true, 'message' => __('Invalid login or password.')]; } /** @var \Magento\Framework\Controller\Result\Json $resultJson */ $resultJson = $this->resultJsonFactory->create(); return $resultJson->setData($response); }
/** * Test execute * * @return void */ public function testExecute() { $data = ['comment' => 'test comment']; $invoiceId = 2; $response = 'some result'; $this->requestMock->expects($this->at(0))->method('getParam')->with('id')->willReturn($invoiceId); $this->requestMock->expects($this->at(1))->method('setParam'); $this->requestMock->expects($this->at(2))->method('getPost')->with('comment')->willReturn($data); $this->requestMock->expects($this->at(3))->method('getParam')->with('invoice_id')->willReturn($invoiceId); $invoiceMock = $this->getMockBuilder('Magento\\Sales\\Model\\Order\\Invoice')->disableOriginalConstructor()->setMethods([])->getMock(); $invoiceMock->expects($this->once())->method('addComment')->with($data['comment'], false, false); $invoiceMock->expects($this->once())->method('save'); $invoiceMock->expects($this->once())->method('load')->willReturnSelf(); $this->objectManagerMock->expects($this->once())->method('create')->with('Magento\\Sales\\Model\\Order\\Invoice')->willReturn($invoiceMock); $commentsBlockMock = $this->getMockBuilder('Magento\\Sales\\Block\\Adminhtml\\Order\\Invoice\\View\\Comments')->disableOriginalConstructor()->setMethods([])->getMock(); $commentsBlockMock->expects($this->once())->method('toHtml')->will($this->returnValue($response)); $layoutMock = $this->getMockBuilder('Magento\\Framework\\View\\Layout')->disableOriginalConstructor()->setMethods([])->getMock(); $layoutMock->expects($this->once())->method('getBlock')->with('invoice_comments')->will($this->returnValue($commentsBlockMock)); $this->resultPageFactoryMock->expects($this->once())->method('create')->will($this->returnValue($this->resultPageMock)); $this->resultPageMock->expects($this->any())->method('getLayout')->will($this->returnValue($layoutMock)); $this->commentSenderMock->expects($this->once())->method('send')->with($invoiceMock, false, $data['comment']); $resultRaw = $this->getMockBuilder('Magento\\Framework\\Controller\\Result\\Raw')->disableOriginalConstructor()->setMethods([])->getMock(); $resultRaw->expects($this->once())->method('setContents')->with($response); $this->resultRawFactoryMock->expects($this->once())->method('create')->will($this->returnValue($resultRaw)); $this->assertSame($resultRaw, $this->controller->execute()); }
/** * Chooser Source action * * @return \Magento\Framework\Controller\Result\Raw */ public function executeInternal() { $uniqId = $this->getRequest()->getParam('uniq_id'); $massAction = $this->getRequest()->getParam('use_massaction', false); $productTypeId = $this->getRequest()->getParam('product_type_id', null); $layout = $this->layoutFactory->create(); $productsGrid = $layout->createBlock('Magento\\Catalog\\Block\\Adminhtml\\Product\\Widget\\Chooser', '', ['data' => ['id' => $uniqId, 'use_massaction' => $massAction, 'product_type_id' => $productTypeId, 'category_id' => $this->getRequest()->getParam('category_id')]]); $html = $productsGrid->toHtml(); if (!$this->getRequest()->getParam('products_grid')) { $categoriesTree = $layout->createBlock('Magento\\Catalog\\Block\\Adminhtml\\Category\\Widget\\Chooser', '', ['data' => ['id' => $uniqId . 'Tree', 'node_click_listener' => $productsGrid->getCategoryClickListenerJs(), 'with_empty_node' => true]]); $html = $layout->createBlock('Magento\\Catalog\\Block\\Adminhtml\\Product\\Widget\\Chooser\\Container')->setTreeHtml($categoriesTree->toHtml())->setGridHtml($html)->toHtml(); } /** @var \Magento\Framework\Controller\Result\Raw $resultRaw */ $resultRaw = $this->resultRawFactory->create(); return $resultRaw->setContents($html); }
/** * 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; } }
/** * Test execute * * @return void */ public function testExecute() { $orderId = 1; $invoiceData = ['comment_text' => 'test']; $response = 'test data'; $this->requestMock->expects($this->at(0))->method('getParam')->with('order_id')->will($this->returnValue($orderId)); $this->requestMock->expects($this->at(1))->method('getParam')->with('invoice', [])->will($this->returnValue($invoiceData)); $invoiceMock = $this->getMockBuilder('Magento\\Sales\\Model\\Order\\Invoice')->disableOriginalConstructor()->setMethods([])->getMock(); $invoiceMock->expects($this->once())->method('getTotalQty')->willReturn(2); $orderMock = $this->getMockBuilder('Magento\\Sales\\Model\\Order')->disableOriginalConstructor()->setMethods(['load', 'getId', 'canInvoice'])->getMock(); $orderMock->expects($this->once())->method('load')->with($orderId)->willReturnSelf(); $orderMock->expects($this->once())->method('getId')->willReturn($orderId); $orderMock->expects($this->once())->method('canInvoice')->willReturn(true); $this->invoiceServiceMock->expects($this->once())->method('prepareInvoice')->with($orderMock, [])->willReturn($invoiceMock); $this->objectManagerMock->expects($this->at(0))->method('create')->with('Magento\\Sales\\Model\\Order')->willReturn($orderMock); $blockItemMock = $this->getMockBuilder('Magento\\Sales\\Block\\Order\\Items')->disableOriginalConstructor()->setMethods([])->getMock(); $blockItemMock->expects($this->once())->method('toHtml')->will($this->returnValue($response)); $layoutMock = $this->getMockBuilder('Magento\\Framework\\View\\Layout')->disableOriginalConstructor()->setMethods([])->getMock(); $layoutMock->expects($this->once())->method('getBlock')->with('order_items')->will($this->returnValue($blockItemMock)); $this->resultPageMock->expects($this->once())->method('getLayout')->will($this->returnValue($layoutMock)); $this->resultPageMock->expects($this->once())->method('getConfig')->will($this->returnValue($this->pageConfigMock)); $this->pageConfigMock->expects($this->once())->method('getTitle')->will($this->returnValue($this->titleMock)); $this->resultPageFactoryMock->expects($this->once())->method('create')->will($this->returnValue($this->resultPageMock)); $resultRaw = $this->getMockBuilder('Magento\\Framework\\Controller\\Result\\Raw')->disableOriginalConstructor()->setMethods([])->getMock(); $resultRaw->expects($this->once())->method('setContents')->with($response); $this->resultRawFactoryMock->expects($this->once())->method('create')->will($this->returnValue($resultRaw)); $this->assertSame($resultRaw, $this->controller->execute()); }
protected function initRawResult() { if (!is_null($this->rawResult)) { return; } $this->rawResult = $this->resultRawFactory->create(); }
/** * Download backup action * * @return void|\Magento\Backend\App\Action */ public function executeInternal() { /* @var $backup \Magento\Backup\Model\Backup */ $backup = $this->_backupModelFactory->create($this->getRequest()->getParam('time'), $this->getRequest()->getParam('type')); if (!$backup->getTime() || !$backup->exists()) { /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ $resultRedirect = $this->resultRedirectFactory->create(); $resultRedirect->setPath('backup/*'); return $resultRedirect; } $fileName = $this->_objectManager->get('Magento\\Backup\\Helper\\Data')->generateBackupDownloadName($backup); $this->_fileFactory->create($fileName, null, DirectoryList::VAR_DIR, 'application/octet-stream', $backup->getSize()); /** @var \Magento\Framework\Controller\Result\Raw $resultRaw */ $resultRaw = $this->resultRawFactory->create(); $resultRaw->setContents($backup->output()); return $resultRaw; }
/** * Download backup action * * @return void|\Magento\Backend\App\Action */ public function execute() { $fileName = $this->getRequest()->getParam('filename'); /** @var \Magento\ImportExport\Helper\Report $reportHelper */ $reportHelper = $this->_objectManager->get('Magento\\ImportExport\\Helper\\Report'); if (!$reportHelper->importFileExists($fileName)) { /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ $resultRedirect = $this->resultRedirectFactory->create(); $resultRedirect->setPath('*/history'); return $resultRedirect; } $this->fileFactory->create($fileName, null, DirectoryList::VAR_DIR, 'application/octet-stream', $reportHelper->getReportSize($fileName)); /** @var \Magento\Framework\Controller\Result\Raw $resultRaw */ $resultRaw = $this->resultRawFactory->create(); $resultRaw->setContents($reportHelper->getReportOutput($fileName)); return $resultRaw; }
/** * Test execute * * @return void */ public function testExecute() { $comment = 'Test comment'; $data = ['comment' => $comment]; $html = 'test output'; $creditmemoMock = $this->getMockBuilder('Magento\Sales\Model\Order\Creditmemo') ->disableOriginalConstructor() ->getMock(); $commentMock = $this->getMockBuilder('Magento\Sales\Model\Order\Creditmemo\Comment') ->disableOriginalConstructor() ->getMock(); $layoutMock = $this->getMockBuilder('Magento\Framework\View\Layout') ->disableOriginalConstructor() ->getMock(); $blockMock = $this->getMockBuilder('Magento\Sales\Block\Adminhtml\Order\Creditmemo\View\Comments') ->disableOriginalConstructor() ->getMock(); $this->requestMock->expects($this->once()) ->method('getPost') ->with('comment') ->willReturn($data); $this->requestMock->expects($this->any()) ->method('getParam') ->willReturnArgument(0); $creditmemoMock->expects($this->once()) ->method('addComment') ->willReturn($commentMock); $this->loaderMock->expects($this->once()) ->method('load') ->willReturn($creditmemoMock); $this->resultPageFactoryMock->expects($this->once()) ->method('create') ->willReturn($this->resultPageMock); $this->resultPageMock->expects($this->atLeastOnce()) ->method('getLayout') ->willReturn($layoutMock); $layoutMock->expects($this->once()) ->method('getBlock') ->with('creditmemo_comments') ->willReturn($blockMock); $blockMock->expects($this->once()) ->method('toHtml') ->willReturn($html); $this->resultRawFactoryMock->expects($this->once()) ->method('create') ->willReturn($this->resultRawMock); $this->resultRawMock->expects($this->once()) ->method('setContents') ->with($html) ->willReturnSelf(); $this->assertInstanceOf( 'Magento\Framework\Controller\Result\Raw', $this->controller->executeInternal() ); }
/** * Generate image thumbnail on the fly * * @return \Magento\Framework\Controller\Result\Raw */ public function execute() { $file = $this->getRequest()->getParam('file'); $file = $this->_objectManager->get('Magento\\Cms\\Helper\\Wysiwyg\\Images')->idDecode($file); $thumb = $this->getStorage()->resizeOnTheFly($file); /** @var \Magento\Framework\Controller\Result\Raw $resultRaw */ $resultRaw = $this->resultRawFactory->create(); if ($thumb !== false) { /** @var \Magento\Framework\Image\Adapter\AdapterInterface $image */ $image = $this->_objectManager->get('Magento\\Framework\\Image\\AdapterFactory')->create(); $image->open($thumb); $resultRaw->setHeader('Content-Type', $image->getMimeType()); $resultRaw->setContents($image->getImage()); return $resultRaw; } else { // todo: generate some placeholder } }
/** * Download sample file action * * @return \Magento\Framework\Controller\Result\Raw */ public function execute() { $fileName = $this->getRequest()->getParam('filename') . '.csv'; $filePath = self::SAMPLE_FILES_DIRECTORY . $fileName; if (!$this->fileDirectory->isFile($filePath)) { /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ $this->messageManager->addError(__('There is no sample file for this entity.')); $resultRedirect = $this->resultRedirectFactory->create(); $resultRedirect->setPath('*/import'); return $resultRedirect; } $fileSize = isset($this->fileDirectory->stat($filePath)['size']) ? $this->fileDirectory->stat($filePath)['size'] : null; $this->fileFactory->create($fileName, null, DirectoryList::VAR_DIR, 'application/octet-stream', $fileSize); /** @var \Magento\Framework\Controller\Result\Raw $resultRaw */ $resultRaw = $this->resultRawFactory->create(); $resultRaw->setContents($this->fileDirectory->readFile($filePath)); return $resultRaw; }
/** * Set up */ public function setUp() { $this->contextMock = $this->getMock('\\Magento\\Backend\\App\\Action\\Context', [], [], '', false); $this->rawFactoryMock = $this->getMock('\\Magento\\Framework\\Controller\\Result\\RawFactory', ['create'], [], '', false); $response = $this->getMock('\\Magento\\Framework\\Controller\\Result\\Raw', [], [], '', false); $this->rawFactoryMock->expects($this->once())->method('create')->willReturn($response); $this->configMock = $this->getMock('\\Magento\\Catalog\\Model\\Product\\Media\\Config', [], [], '', false); $this->filesystemMock = $this->getMock('\\Magento\\Framework\\Filesystem', [], [], '', false); $this->adapterMock = $this->getMock('\\Magento\\Framework\\Image', [], [], '', false); $this->adapterFactoryMock = $this->getMock('\\Magento\\Framework\\Image\\AdapterFactory', ['create'], [], '', false); $this->abstractAdapter = $this->getMock('\\Magento\\Framework\\Image\\Adapter\\AbstractAdapter', [], [], '', false); $this->adapterFactoryMock->expects($this->once())->method('create')->willReturn($this->abstractAdapter); $this->curlMock = $this->getMock('\\Magento\\Framework\\HTTP\\Adapter\\Curl', [], [], '', false); $this->storageFileMock = $this->getMock('\\Magento\\MediaStorage\\Model\\ResourceModel\\File\\Storage\\File', [], [], '', false); $this->request = $this->getMock('\\Magento\\Framework\\App\\RequestInterface'); $this->contextMock->expects($this->any())->method('getRequest')->will($this->returnValue($this->request)); $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); $this->image = $objectManager->getObject('\\Magento\\ProductVideo\\Controller\\Adminhtml\\Product\\Gallery\\RetrieveImage', ['context' => $this->contextMock, 'resultRawFactory' => $this->rawFactoryMock, 'mediaConfig' => $this->configMock, 'fileSystem' => $this->filesystemMock, 'imageAdapterFactory' => $this->adapterFactoryMock, 'curl' => $this->curlMock, 'fileUtility' => $this->storageFileMock]); }
/** * @inheritDoc */ public function processNotification($payuplOrderId, $status, $amount) { /** * @var $result \Magento\Framework\Controller\Result\Raw */ $newest = $this->transactionResource->checkIfNewestByPayuplOrderId($payuplOrderId); $this->orderProcessor->processStatusChange($payuplOrderId, $status, $amount, $newest); $result = $this->rawResultFactory->create(); $result->setHttpResponseCode(200)->setContents('OK'); return $result; }
/** * Download sample file action * * @return \Magento\Framework\Controller\Result\Raw */ public function executeInternal() { $fileName = $this->getRequest()->getParam('filename') . '.csv'; $moduleDir = $this->componentRegistrar->getPath(ComponentRegistrar::MODULE, self::SAMPLE_FILES_MODULE); $fileAbsolutePath = $moduleDir . '/Files/Sample/' . $fileName; $directoryRead = $this->readFactory->create($moduleDir); $filePath = $directoryRead->getRelativePath($fileAbsolutePath); if (!$directoryRead->isFile($filePath)) { /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ $this->messageManager->addError(__('There is no sample file for this entity.')); $resultRedirect = $this->resultRedirectFactory->create(); $resultRedirect->setPath('*/import'); return $resultRedirect; } $fileSize = isset($directoryRead->stat($filePath)['size']) ? $directoryRead->stat($filePath)['size'] : null; $this->fileFactory->create($fileName, null, DirectoryList::VAR_DIR, 'application/octet-stream', $fileSize); /** @var \Magento\Framework\Controller\Result\Raw $resultRaw */ $resultRaw = $this->resultRawFactory->create(); $resultRaw->setContents($directoryRead->readFile($filePath)); return $resultRaw; }