/**
  * 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);
     }
 }
Beispiel #2
0
 /**
  * @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;
 }
Beispiel #3
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;
     }
 }
Beispiel #4
0
 /**
  * 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;
 }
Beispiel #5
0
 /**
  * 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);
 }
Beispiel #6
0
 /**
  * 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());
 }
Beispiel #7
0
 /**
  * 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');
     }
 }
 /**
  * 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());
 }
Beispiel #9
0
 /**
  * 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());
 }
Beispiel #10
0
 /**
  * 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;
 }
Beispiel #12
0
 /**
  * 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));
 }
Beispiel #17
0
 /**
  * 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);
 }
Beispiel #18
0
 protected function initRawResult()
 {
     if (!is_null($this->rawResult)) {
         return;
     }
     $this->rawResult = $this->resultRawFactory->create();
 }
Beispiel #19
0
 /**
  * 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);
 }
 /**
  * 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;
     }
 }
Beispiel #21
0
 /**
  * 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;
 }
Beispiel #22
0
 /**
  * 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;
 }
Beispiel #23
0
 /**
  * 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;
 }
 /**
  * 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
     }
 }
Beispiel #25
0
 /**
  * @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;
 }
Beispiel #26
0
 /**
  * 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;
 }
 /**
  * @return \Magento\Framework\Controller\Result\Raw
  */
 public function execute()
 {
     try {
         $remoteFileUrl = $this->getRequest()->getParam('remote_image');
         $originalFileName = $this->parseOriginalFileName($remoteFileUrl);
         $localFileName = $this->localFileName($originalFileName);
         $localTmpFileName = $this->generateTmpFileName($localFileName);
         $localFileMediaPath = $this->appendFileSystemPath($localTmpFileName);
         $localUniqueFileMediaPath = $this->appendNewFileName($localFileMediaPath);
         $this->retrieveRemoteImage($remoteFileUrl, $localUniqueFileMediaPath);
         $localFileFullPath = $this->appendAbsoluteFileSystemPath($localUniqueFileMediaPath);
         $this->imageAdapter->validateUploadFile($localFileFullPath);
         $result = $this->appendResultSaveRemoteImage($localUniqueFileMediaPath);
     } 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;
 }
 /**
  * Template directives callback
  *
  * @return \Magento\Framework\Controller\Result\Raw
  */
 public function execute()
 {
     $directive = $this->getRequest()->getParam('___directive');
     $directive = $this->urlDecoder->decode($directive);
     $imagePath = $this->_objectManager->create('Stepzerosolutions\\Tbslider\\Model\\Template\\Filter')->filter($directive);
     /** @var \Magento\Framework\Image\Adapter\AdapterInterface $image */
     $image = $this->_objectManager->get('Magento\\Framework\\Image\\AdapterFactory')->create();
     /** @var \Magento\Framework\Controller\Result\Raw $resultRaw */
     $resultRaw = $this->resultRawFactory->create();
     try {
         $image->open($imagePath);
         $resultRaw->setHeader('Content-Type', $image->getMimeType());
         $resultRaw->setContents($image->getImage());
     } catch (\Exception $e) {
         $imagePath = $this->_objectManager->get('Stepzerosolutions\\Tbslider\\Model\\Wysiwyg\\Config')->getSkinImagePlaceholderPath();
         $image->open($imagePath);
         $resultRaw->setHeader('Content-Type', $image->getMimeType());
         $resultRaw->setContents($image->getImage());
         $this->_objectManager->get('Psr\\Log\\LoggerInterface')->critical($e);
     }
     return $resultRaw;
 }
Beispiel #29
0
    /**
     * Update items qty action
     *
     * @return \Magento\Framework\Controller\ResultInterface
     */
    public function executeInternal()
    {
        try {
            $orderId = $this->getRequest()->getParam('order_id');
            $invoiceData = $this->getRequest()->getParam('invoice', []);
            $invoiceItems = isset($invoiceData['items']) ? $invoiceData['items'] : [];
            /** @var \Magento\Sales\Model\Order $order */
            $order = $this->_objectManager->create('Magento\Sales\Model\Order')->load($orderId);
            if (!$order->getId()) {
                throw new \Magento\Framework\Exception\LocalizedException(__('The order no longer exists.'));
            }

            if (!$order->canInvoice()) {
                throw new \Magento\Framework\Exception\LocalizedException(
                    __('The order does not allow an invoice to be created.')
                );
            }

            $invoice = $this->invoiceService->prepareInvoice($order, $invoiceItems);

            if (!$invoice->getTotalQty()) {
                throw new \Magento\Framework\Exception\LocalizedException(
                    __('You can\'t create an invoice without products.')
                );
            }
            $this->registry->register('current_invoice', $invoice);
            // Save invoice comment text in current invoice object in order to display it in corresponding view
            $invoiceRawCommentText = $invoiceData['comment_text'];
            $invoice->setCommentText($invoiceRawCommentText);

            /** @var \Magento\Backend\Model\View\Result\Page $resultPage */
            $resultPage = $this->resultPageFactory->create();
            $resultPage->getConfig()->getTitle()->prepend(__('Invoices'));
            $response = $resultPage->getLayout()->getBlock('order_items')->toHtml();
        } catch (LocalizedException $e) {
            $response = ['error' => true, 'message' => $e->getMessage()];
        } catch (\Exception $e) {
            $response = ['error' => true, 'message' => __('Cannot update item quantity.')];
        }
        if (is_array($response)) {
            /** @var \Magento\Framework\Controller\Result\Json $resultJson */
            $resultJson = $this->resultJsonFactory->create();
            $resultJson->setData($response);
            return $resultJson;
        } else {
            /** @var \Magento\Framework\Controller\Result\Raw $resultRaw */
            $resultRaw = $this->resultRawFactory->create();
            $resultRaw->setContents($response);
            return $resultRaw;
        }
    }
Beispiel #30
0
 /**
  * Customer view file action
  *
  * @return void
  * @throws NotFoundException
  *
  * @SuppressWarnings(PHPMD.ExitExpression)
  */
 public function executeInternal()
 {
     $file = null;
     $plain = false;
     if ($this->getRequest()->getParam('file')) {
         // download file
         $file = $this->urlDecoder->decode($this->getRequest()->getParam('file'));
     } elseif ($this->getRequest()->getParam('image')) {
         // show plain image
         $file = $this->urlDecoder->decode($this->getRequest()->getParam('image'));
         $plain = true;
     } else {
         throw new NotFoundException(__('Page not found.'));
     }
     /** @var \Magento\Framework\Filesystem $filesystem */
     $filesystem = $this->_objectManager->get('Magento\\Framework\\Filesystem');
     $directory = $filesystem->getDirectoryRead(DirectoryList::MEDIA);
     $fileName = 'customer' . '/' . ltrim($file, '/');
     $path = $directory->getAbsolutePath($fileName);
     if (!$directory->isFile($fileName) && !$this->_objectManager->get('Magento\\MediaStorage\\Helper\\File\\Storage')->processStorageFile($path)) {
         throw new NotFoundException(__('Page not found.'));
     }
     if ($plain) {
         $extension = pathinfo($path, PATHINFO_EXTENSION);
         switch (strtolower($extension)) {
             case 'gif':
                 $contentType = 'image/gif';
                 break;
             case 'jpg':
                 $contentType = 'image/jpeg';
                 break;
             case 'png':
                 $contentType = 'image/png';
                 break;
             default:
                 $contentType = 'application/octet-stream';
                 break;
         }
         $stat = $directory->stat($path);
         $contentLength = $stat['size'];
         $contentModify = $stat['mtime'];
         /** @var \Magento\Framework\Controller\Result\Raw $resultRaw */
         $resultRaw = $this->resultRawFactory->create();
         $resultRaw->setHttpResponseCode(200)->setHeader('Pragma', 'public', true)->setHeader('Content-type', $contentType, true)->setHeader('Content-Length', $contentLength)->setHeader('Last-Modified', date('r', $contentModify));
         $resultRaw->setContents($directory->readFile($fileName));
         return $resultRaw;
     } else {
         $name = pathinfo($path, PATHINFO_BASENAME);
         $this->_fileFactory->create($name, ['type' => 'filename', 'value' => $fileName], DirectoryList::MEDIA);
     }
 }