Ejemplo n.º 1
1
 /**
  * Redirect to order view page
  *
  * @param int $orderId
  * @return \Magento\Backend\Model\View\Result\Redirect
  */
 protected function _redirectToOrder($orderId)
 {
     /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
     $resultRedirect = $this->resultRedirectFactory->create();
     $resultRedirect->setPath('sales/order/view', ['order_id' => $orderId]);
     return $resultRedirect;
 }
Ejemplo n.º 2
0
 /**
  * Edit CMS page
  *
  * @return \Magento\Backend\Model\View\Result\Page|\Magento\Backend\Model\View\Result\Redirect
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function execute()
 {
     // 1. Get ID and create model
     $id = $this->getRequest()->getParam('page_id');
     $model = $this->_objectManager->create('Magento\\Cms\\Model\\Page');
     // 2. Initial checking
     if ($id) {
         $model->load($id);
         if (!$model->getId()) {
             $this->messageManager->addError(__('This page no longer exists.'));
             /** \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
             $resultRedirect = $this->resultRedirectFactory->create();
             return $resultRedirect->setPath('*/*/');
         }
     }
     // 3. Set entered data if was error when we do save
     $data = $this->_objectManager->get('Magento\\Backend\\Model\\Session')->getFormData(true);
     if (!empty($data)) {
         $model->setData($data);
     }
     // 4. Register model to use later in blocks
     $this->_coreRegistry->register('cms_page', $model);
     // 5. Build edit form
     /** @var \Magento\Backend\Model\View\Result\Page $resultPage */
     $resultPage = $this->_initAction();
     $resultPage->addBreadcrumb($id ? __('Edit Page') : __('New Page'), $id ? __('Edit Page') : __('New Page'));
     $resultPage->getConfig()->getTitle()->prepend(__('Pages'));
     $resultPage->getConfig()->getTitle()->prepend($model->getId() ? $model->getTitle() : __('New Page'));
     return $resultPage;
 }
Ejemplo n.º 3
0
 /**
  * Product edit form
  *
  * @return \Magento\Framework\Controller\ResultInterface
  */
 public function execute()
 {
     $productId = (int) $this->getRequest()->getParam('id');
     $product = $this->productBuilder->build($this->getRequest());
     if ($productId && !$product->getId()) {
         $this->messageManager->addError(__('This product no longer exists.'));
         /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
         $resultRedirect = $this->resultRedirectFactory->create();
         return $resultRedirect->setPath('catalog/*/');
     }
     $this->_eventManager->dispatch('catalog_product_edit_action', ['product' => $product]);
     /** @var \Magento\Backend\Model\View\Result\Page $resultPage */
     $resultPage = $this->resultPageFactory->create();
     $resultPage->addHandle('catalog_product_' . $product->getTypeId());
     $resultPage->setActiveMenu('Magento_Catalog::catalog_products');
     $resultPage->getConfig()->getTitle()->prepend(__('Products'));
     $resultPage->getConfig()->getTitle()->prepend($product->getName());
     if (!$this->_objectManager->get('Magento\\Store\\Model\\StoreManagerInterface')->isSingleStoreMode() && ($switchBlock = $resultPage->getLayout()->getBlock('store_switcher'))) {
         $switchBlock->setDefaultStoreName(__('Default Values'))->setWebsiteIds($product->getWebsiteIds())->setSwitchUrl($this->getUrl('catalog/*/*', ['_current' => true, 'active_tab' => null, 'tab' => null, 'store' => null]));
     }
     $block = $resultPage->getLayout()->getBlock('catalog.wysiwyg.js');
     if ($block) {
         $block->setStoreId($product->getStoreId());
     }
     return $resultPage;
 }
Ejemplo n.º 4
0
 /**
  * Delete action
  *
  * @return \Magento\Backend\Model\View\Result\Redirect
  */
 public function execute()
 {
     // check if we know what should be deleted
     $id = $this->getRequest()->getParam('page_id');
     /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
     $resultRedirect = $this->resultRedirectFactory->create();
     if ($id) {
         $title = "";
         try {
             // init model and delete
             $model = $this->_objectManager->create('Magento\\Cms\\Model\\Page');
             $model->load($id);
             $title = $model->getTitle();
             $model->delete();
             // display success message
             $this->messageManager->addSuccess(__('The page has been deleted.'));
             // go to grid
             $this->_eventManager->dispatch('adminhtml_cmspage_on_delete', ['title' => $title, 'status' => 'success']);
             return $resultRedirect->setPath('*/*/');
         } catch (\Exception $e) {
             $this->_eventManager->dispatch('adminhtml_cmspage_on_delete', ['title' => $title, 'status' => 'fail']);
             // display error message
             $this->messageManager->addError($e->getMessage());
             // go back to edit form
             return $resultRedirect->setPath('*/*/edit', ['page_id' => $id]);
         }
     }
     // display error message
     $this->messageManager->addError(__('We can\'t find a page to delete.'));
     // go to grid
     return $resultRedirect->setPath('*/*/');
 }
Ejemplo n.º 5
0
 /**
  * Save product action
  *
  * @return \Magento\Backend\Model\View\Result\Redirect
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 public function execute()
 {
     $storeId = $this->getRequest()->getParam('store');
     $redirectBack = $this->getRequest()->getParam('back', false);
     $productId = $this->getRequest()->getParam('id');
     $resultRedirect = $this->resultRedirectFactory->create();
     $data = $this->getRequest()->getPostValue();
     if ($data) {
         try {
             $product = $this->initializationHelper->initialize($this->productBuilder->build($this->getRequest()));
             $this->productTypeManager->processProduct($product);
             if (isset($data['product'][$product->getIdFieldName()])) {
                 throw new \Magento\Framework\Exception\LocalizedException(__('Unable to save product'));
             }
             $originalSku = $product->getSku();
             $product->save();
             $productId = $product->getId();
             /**
              * Do copying data to stores
              */
             if (isset($data['copy_to_stores'])) {
                 foreach ($data['copy_to_stores'] as $storeTo => $storeFrom) {
                     $this->_objectManager->create('Magento\\Catalog\\Model\\Product')->setStoreId($storeFrom)->load($productId)->setStoreId($storeTo)->save();
                 }
             }
             $this->messageManager->addSuccess(__('You saved the product.'));
             if ($product->getSku() != $originalSku) {
                 $this->messageManager->addNotice(__('SKU for product %1 has been changed to %2.', $this->_objectManager->get('Magento\\Framework\\Escaper')->escapeHtml($product->getName()), $this->_objectManager->get('Magento\\Framework\\Escaper')->escapeHtml($product->getSku())));
             }
             $this->_eventManager->dispatch('controller_action_catalog_product_save_entity_after', ['controller' => $this]);
             if ($redirectBack === 'duplicate') {
                 $newProduct = $this->productCopier->copy($product);
                 $this->messageManager->addSuccess(__('You duplicated the product.'));
             }
         } catch (\Magento\Framework\Exception\LocalizedException $e) {
             $this->messageManager->addError($e->getMessage());
             $this->_session->setProductData($data);
             $redirectBack = $productId ? true : 'new';
         } catch (\Exception $e) {
             $this->_objectManager->get('Psr\\Log\\LoggerInterface')->critical($e);
             $this->messageManager->addError($e->getMessage());
             $this->_session->setProductData($data);
             $redirectBack = $productId ? true : 'new';
         }
     } else {
         $resultRedirect->setPath('catalog/*/', ['store' => $storeId]);
         $this->messageManager->addError('No data to save');
         return $resultRedirect;
     }
     if ($redirectBack === 'new') {
         $resultRedirect->setPath('catalog/*/new', ['set' => $product->getAttributeSetId(), 'type' => $product->getTypeId()]);
     } elseif ($redirectBack === 'duplicate' && isset($newProduct)) {
         $resultRedirect->setPath('catalog/*/edit', ['id' => $newProduct->getId(), 'back' => null, '_current' => true]);
     } elseif ($redirectBack) {
         $resultRedirect->setPath('catalog/*/edit', ['id' => $productId, '_current' => true]);
     } else {
         $resultRedirect->setPath('catalog/*/', ['store' => $storeId]);
     }
     return $resultRedirect;
 }
Ejemplo n.º 6
0
 /**
  * Void creditmemo action
  *
  * @return \Magento\Backend\Model\View\Result\Redirect|\Magento\Backend\Model\View\Result\Forward
  */
 public function execute()
 {
     $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();
     if ($creditmemo) {
         try {
             $creditmemo->void();
             $transactionSave = $this->_objectManager->create('Magento\\Framework\\DB\\Transaction');
             $transactionSave->addObject($creditmemo);
             $transactionSave->addObject($creditmemo->getOrder());
             if ($creditmemo->getInvoice()) {
                 $transactionSave->addObject($creditmemo->getInvoice());
             }
             $transactionSave->save();
             $this->messageManager->addSuccess(__('You voided the credit memo.'));
         } catch (\Magento\Framework\Exception\LocalizedException $e) {
             $this->messageManager->addError($e->getMessage());
         } catch (\Exception $e) {
             $this->messageManager->addError(__('We can\'t void the credit memo.'));
         }
         $resultRedirect = $this->resultRedirectFactory->create();
         $resultRedirect->setPath('sales/*/view', ['creditmemo_id' => $creditmemo->getId()]);
         return $resultRedirect;
     } else {
         $resultForward = $this->resultForwardFactory->create();
         $resultForward->forward('noroute');
         return $resultForward;
     }
 }
Ejemplo n.º 7
0
 /**
  * Delete action
  *
  * @return \Magento\Framework\Controller\ResultInterface
  */
 public function execute()
 {
     /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
     $resultRedirect = $this->resultRedirectFactory->create();
     // check if we know what should be deleted
     $id = $this->getRequest()->getParam('block_id');
     if ($id) {
         try {
             // init model and delete
             $model = $this->_objectManager->create('Magento\\Cms\\Model\\Block');
             $model->load($id);
             $model->delete();
             // display success message
             $this->messageManager->addSuccess(__('The block has been deleted.'));
             // go to grid
             return $resultRedirect->setPath('*/*/');
         } catch (\Exception $e) {
             // display error message
             $this->messageManager->addError($e->getMessage());
             // go back to edit form
             return $resultRedirect->setPath('*/*/edit', ['block_id' => $id]);
         }
     }
     // display error message
     $this->messageManager->addError(__('We can\'t find a block to delete.'));
     // go to grid
     return $resultRedirect->setPath('*/*/');
 }
Ejemplo n.º 8
0
 /**
  * @return \Magento\Framework\Controller\ResultInterface
  */
 public function execute()
 {
     if (!$this->_validateProducts()) {
         return $this->resultRedirectFactory->create()->setPath('catalog/product/', ['_current' => true]);
     }
     return $this->resultPageFactory->create();
 }
Ejemplo n.º 9
0
 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]);
 }
Ejemplo n.º 10
0
 /**
  * Save status assignment to state
  *
  * @return \Magento\Backend\Model\View\Result\Redirect
  */
 public function execute()
 {
     $data = $this->getRequest()->getPostValue();
     /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
     $resultRedirect = $this->resultRedirectFactory->create();
     if ($data) {
         $state = $this->getRequest()->getParam('state');
         $isDefault = $this->getRequest()->getParam('is_default');
         $visibleOnFront = $this->getRequest()->getParam('visible_on_front');
         $status = $this->_initStatus();
         if ($status && $status->getStatus()) {
             try {
                 $status->assignState($state, $isDefault, $visibleOnFront);
                 $this->messageManager->addSuccess(__('You have assigned the order status.'));
                 return $resultRedirect->setPath('sales/*/');
             } catch (\Magento\Framework\Exception\LocalizedException $e) {
                 $this->messageManager->addError($e->getMessage());
             } catch (\Exception $e) {
                 $this->messageManager->addException($e, __('An error occurred while assigning order status. Status has not been assigned.'));
             }
         } else {
             $this->messageManager->addError(__('We can\'t find this order status.'));
         }
         return $resultRedirect->setPath('sales/*/assign');
     }
     return $resultRedirect->setPath('sales/*/');
 }
Ejemplo n.º 11
0
 public function setUp()
 {
     $objectManagerHelper = new ObjectManagerHelper($this);
     $this->shipmentLoader = $this->getMock('Magento\\Shipping\\Controller\\Adminhtml\\Order\\ShipmentLoader', ['setOrderId', 'setShipmentId', 'setShipment', 'setTracking', 'load'], [], '', false);
     $this->context = $this->getMock('Magento\\Backend\\App\\Action\\Context', ['getRequest', 'getResponse', 'getMessageManager', 'getRedirect', 'getObjectManager', 'getSession', 'getActionFlag', 'getHelper', 'getResultRedirectFactory'], [], '', false);
     $this->response = $this->getMock('Magento\\Framework\\App\\ResponseInterface', ['setRedirect', 'sendResponse'], [], '', false);
     $this->request = $this->getMockBuilder('Magento\\Framework\\App\\RequestInterface')->setMethods(['isPost', 'getModuleName', 'setModuleName', 'getActionName', 'setActionName', 'getParam', 'getCookie'])->getMockForAbstractClass();
     $this->objectManager = $this->getMock('Magento\\Framework\\ObjectManager\\ObjectManager', ['create'], [], '', false);
     $this->messageManager = $this->getMock('Magento\\Framework\\Message\\Manager', ['addSuccess', 'addError'], [], '', false);
     $this->session = $this->getMock('Magento\\Backend\\Model\\Session', ['setIsUrlNotice'], [], '', false);
     $this->actionFlag = $this->getMock('Magento\\Framework\\App\\ActionFlag', ['get'], [], '', false);
     $this->helper = $this->getMock('\\Magento\\Backend\\Helper\\Data', ['getUrl'], [], '', false);
     $this->resultRedirect = $this->getMock('Magento\\Backend\\Model\\View\\Result\\Redirect', [], [], '', false);
     $this->resultRedirectFactory = $this->getMock('Magento\\Backend\\Model\\View\\Result\\RedirectFactory', ['create'], [], '', false);
     $this->resultRedirectFactory->expects($this->once())->method('create')->willReturn($this->resultRedirect);
     $this->context->expects($this->once())->method('getMessageManager')->willReturn($this->messageManager);
     $this->context->expects($this->once())->method('getRequest')->willReturn($this->request);
     $this->context->expects($this->once())->method('getResponse')->willReturn($this->response);
     $this->context->expects($this->once())->method('getObjectManager')->willReturn($this->objectManager);
     $this->context->expects($this->once())->method('getSession')->willReturn($this->session);
     $this->context->expects($this->once())->method('getActionFlag')->willReturn($this->actionFlag);
     $this->context->expects($this->once())->method('getHelper')->willReturn($this->helper);
     $this->context->expects($this->once())->method('getResultRedirectFactory')->willReturn($this->resultRedirectFactory);
     $this->shipmentEmail = $objectManagerHelper->getObject('Magento\\Shipping\\Controller\\Adminhtml\\Order\\Shipment\\Email', ['context' => $this->context, 'shipmentLoader' => $this->shipmentLoader, 'request' => $this->request, 'response' => $this->response]);
 }
Ejemplo n.º 12
0
 /**
  * Administrator logout action
  *
  * @return \Magento\Backend\Model\View\Result\Redirect
  */
 public function execute()
 {
     $this->_auth->logout();
     $this->messageManager->addSuccess(__('You have logged out.'));
     /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
     $resultRedirect = $this->resultRedirectFactory->create();
     return $resultRedirect->setPath($this->_helper->getHomePageUrl());
 }
 public function testExecute()
 {
     $path = '*/*';
     $this->resultRedirectFactory->expects($this->any())->method('create')->willReturn($this->resultRedirect);
     $this->messageManager->expects($this->once())->method('addSuccess')->with(__('We updated lifetime statistic.'));
     $this->objectManager->expects($this->any())->method('create')->with('Magento\\Sales\\Model\\Resource\\Report\\Order')->willReturn($this->order);
     $this->resultRedirect->expects($this->once())->method('setPath')->with($path)->willReturnSelf();
     $this->assertInstanceOf('Magento\\Backend\\Model\\View\\Result\\Redirect', $this->refreshStatisticsController->execute());
 }
Ejemplo n.º 14
0
 /**
  * Start create creditmemo action
  *
  * @return \Magento\Backend\Model\View\Result\Redirect
  */
 public function execute()
 {
     /**
      * Clear old values for creditmemo qty's
      */
     $resultRedirect = $this->resultRedirectFactory->create();
     $resultRedirect->setPath('sales/*/new', ['_current' => true]);
     return $resultRedirect;
 }
Ejemplo n.º 15
0
 /**
  * Start create invoice action
  *
  * @return \Magento\Framework\Controller\ResultInterface
  */
 public function execute()
 {
     /**
      * Clear old values for invoice qty's
      */
     $this->_getSession()->getInvoiceItemQtys(true);
     /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
     $resultRedirect = $this->resultRedirectFactory->create();
     $resultRedirect->setPath('sales/*/new', ['order_id' => $this->getRequest()->getParam('order_id')]);
     return $resultRedirect;
 }
Ejemplo n.º 16
0
 public function testEditActionBlockNoExists()
 {
     $blockId = 1;
     $this->requestMock->expects($this->once())->method('getParam')->with('block_id')->willReturn($blockId);
     $this->blockMock->expects($this->once())->method('load')->with($blockId);
     $this->blockMock->expects($this->once())->method('getId')->willReturn(null);
     $this->messageManagerMock->expects($this->once())->method('addError')->with(__('This block no longer exists.'));
     $this->resultRedirectFactoryMock->expects($this->atLeastOnce())->method('create')->willReturn($this->resultRedirectMock);
     $this->resultRedirectMock->expects($this->once())->method('setPath')->with('*/*/')->willReturnSelf();
     $this->assertSame($this->resultRedirectMock, $this->editController->execute());
 }
Ejemplo n.º 17
0
 protected function setUp()
 {
     $this->attributeHelper = $this->getMock('Magento\\Catalog\\Helper\\Product\\Edit\\Action\\Attribute', ['getProductIds', 'getSelectedStoreId', 'getStoreWebsiteId'], [], '', false);
     $this->dataObjectHelperMock = $this->getMockBuilder('\\Magento\\Framework\\Api\\DataObjectHelper')->disableOriginalConstructor()->getMock();
     $this->stockIndexerProcessor = $this->getMock('Magento\\CatalogInventory\\Model\\Indexer\\Stock\\Processor', ['reindexList'], [], '', false);
     $resultRedirect = $this->getMockBuilder('Magento\\Backend\\Model\\View\\Result\\Redirect')->disableOriginalConstructor()->getMock();
     $this->resultRedirectFactory = $this->getMockBuilder('Magento\\Backend\\Model\\View\\Result\\RedirectFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock();
     $this->resultRedirectFactory->expects($this->atLeastOnce())->method('create')->willReturn($resultRedirect);
     $this->prepareContext();
     $this->object = (new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this))->getObject('Magento\\Catalog\\Controller\\Adminhtml\\Product\\Action\\Attribute\\Save', ['context' => $this->context, 'attributeHelper' => $this->attributeHelper, 'stockIndexerProcessor' => $this->stockIndexerProcessor, 'dataObjectHelper' => $this->dataObjectHelperMock]);
 }
Ejemplo n.º 18
0
 /**
  * Administrator login action
  *
  * @return \Magento\Backend\Model\View\Result\Redirect
  */
 public function execute()
 {
     if ($this->_auth->isLoggedIn()) {
         if ($this->_auth->getAuthStorage()->isFirstPageAfterLogin()) {
             $this->_auth->getAuthStorage()->setIsFirstPageAfterLogin(true);
         }
         /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
         $resultRedirect = $this->resultRedirectFactory->create();
         $resultRedirect->setPath($this->_backendUrl->getStartupPageUrl());
         return $resultRedirect;
     }
     return $this->resultPageFactory->create();
 }
Ejemplo n.º 19
0
 /**
  * @return \Magento\Framework\Controller\ResultInterface
  */
 public function execute()
 {
     if (!$this->_auth->isLoggedIn()) {
         /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
         $resultRedirect = $this->resultRedirectFactory->create();
         $resultRedirect->setStatusHeader(403, '1.1', 'Forbidden');
         return $resultRedirect->setPath('*/auth/login');
     }
     /** @var \Magento\Backend\Model\View\Result\Page $resultPage */
     $resultPage = $this->resultPageFactory->create();
     $resultPage->setStatusHeader(403, '1.1', 'Forbidden');
     $resultPage->addHandle('adminhtml_denied');
     return $resultPage;
 }
Ejemplo n.º 20
0
 /**
  * Notify user
  *
  * @return \Magento\Backend\Model\View\Result\Forward|\Magento\Backend\Model\View\Result\Redirect
  */
 public function execute()
 {
     $invoiceId = $this->getRequest()->getParam('invoice_id');
     if (!$invoiceId) {
         return $this->resultForwardFactory->create()->forward('noroute');
     }
     $invoice = $this->_objectManager->create('Magento\\Sales\\Model\\Order\\Invoice')->load($invoiceId);
     if (!$invoice) {
         return $this->resultForwardFactory->create()->forward('noroute');
     }
     $this->_objectManager->create('Magento\\Sales\\Model\\Order\\InvoiceNotifier')->notify($invoice);
     $this->messageManager->addSuccess(__('We sent the message.'));
     return $this->resultRedirectFactory->create()->setPath('sales/invoice/view', ['order_id' => $invoice->getOrder()->getId(), 'invoice_id' => $invoiceId]);
 }
Ejemplo n.º 21
0
 /**
  * @return \Magento\Backend\Model\View\Result\Redirect
  */
 public function execute()
 {
     $setId = $this->getRequest()->getParam('id');
     $resultRedirect = $this->resultRedirectFactory->create();
     try {
         $this->attributeSetRepository->deleteById($setId);
         $this->messageManager->addSuccess(__('The attribute set has been removed.'));
         $resultRedirect->setPath('catalog/*/');
     } catch (\Exception $e) {
         $this->messageManager->addError(__('An error occurred while deleting this set.'));
         $resultRedirect->setUrl($this->_redirect->getRedirectUrl($this->getUrl('*')));
     }
     return $resultRedirect;
 }
Ejemplo n.º 22
0
 /**
  * @return ResponseInterface|void
  */
 public function execute()
 {
     $invoicesIds = $this->getRequest()->getPost('invoice_ids');
     if (!empty($invoicesIds)) {
         $invoices = $this->_objectManager->create('Magento\\Sales\\Model\\Resource\\Order\\Invoice\\Collection')->addAttributeToSelect('*')->addAttributeToFilter('entity_id', ['in' => $invoicesIds])->load();
         if (!isset($pdf)) {
             $pdf = $this->_objectManager->create('Magento\\Sales\\Model\\Order\\Pdf\\Invoice')->getPdf($invoices);
         } else {
             $pages = $this->_objectManager->create('Magento\\Sales\\Model\\Order\\Pdf\\Invoice')->getPdf($invoices);
             $pdf->pages = array_merge($pdf->pages, $pages->pages);
         }
         $date = $this->_objectManager->get('Magento\\Framework\\Stdlib\\DateTime\\DateTime')->date('Y-m-d_H-i-s');
         return $this->_fileFactory->create('invoice' . $date . '.pdf', $pdf->render(), DirectoryList::VAR_DIR, 'application/pdf');
     }
     return $this->resultRedirectFactory->create()->setPath('sales/*/');
 }
Ejemplo n.º 23
0
    /**
     * @return void
     */
    public function testExecute()
    {
        $creditmemoId = '111';

        $this->requestMock->expects($this->once())
            ->method('getParam')
            ->with('creditmemo_id')
            ->willReturn($creditmemoId);
        $this->objectManagerMock->expects($this->once())
            ->method('create')
            ->with('Magento\Sales\Api\CreditmemoManagementInterface')
            ->willReturn($this->creditmemoManagementMock);
        $this->creditmemoManagementMock->expects($this->once())
            ->method('cancel')
            ->with($creditmemoId);
        $this->messageManagerMock->expects($this->once())
            ->method('addSuccess')
            ->with('The credit memo has been canceled.');
        $this->resultRedirectFactoryMock->expects($this->once())
            ->method('create')
            ->willReturn($this->resultRedirectMock);
        $this->resultRedirectMock->expects($this->once())
            ->method('setPath')
            ->with('sales/*/view', ['creditmemo_id' => $creditmemoId])
            ->willReturnSelf();

        $this->assertInstanceOf(
            'Magento\Backend\Model\View\Result\Redirect',
            $this->controller->executeInternal()
        );
    }
Ejemplo n.º 24
0
 /**
  * Save configuration
  *
  * @return \Magento\Backend\Model\View\Result\Redirect
  */
 public function execute()
 {
     try {
         // custom save logic
         $this->_saveSection();
         $section = $this->getRequest()->getParam('section');
         $website = $this->getRequest()->getParam('website');
         $store = $this->getRequest()->getParam('store');
         $configData = ['section' => $section, 'website' => $website, 'store' => $store, 'groups' => $this->_getGroupsForSave()];
         /** @var \Magento\Config\Model\Config $configModel  */
         $configModel = $this->_configFactory->create(['data' => $configData]);
         $configModel->save();
         $this->messageManager->addSuccess(__('You saved the configuration.'));
     } catch (\Magento\Framework\Exception\LocalizedException $e) {
         $messages = explode("\n", $e->getMessage());
         foreach ($messages as $message) {
             $this->messageManager->addError($message);
         }
     } catch (\Exception $e) {
         $this->messageManager->addException($e, __('An error occurred while saving this configuration:') . ' ' . $e->getMessage());
     }
     $this->_saveState($this->getRequest()->getPost('config_state'));
     /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
     $resultRedirect = $this->resultRedirectFactory->create();
     return $resultRedirect->setPath('adminhtml/system_config/edit', ['_current' => ['section', 'website', 'store'], '_nosid' => true]);
 }
Ejemplo n.º 25
0
 /**
  * Notify user
  *
  * @return \Magento\Backend\Model\View\Result\Redirect
  */
 public function execute()
 {
     $creditmemoId = $this->getRequest()->getParam('creditmemo_id');
     if (!$creditmemoId) {
         return;
     }
     $creditmemo = $this->_objectManager->create('Magento\\Sales\\Model\\Order\\Creditmemo')->load($creditmemoId);
     if (!$creditmemo) {
         return;
     }
     $this->_objectManager->create('Magento\\Sales\\Model\\Order\\CreditmemoNotifier')->notify($creditmemo);
     $this->messageManager->addSuccess(__('We sent the message.'));
     $resultRedirect = $this->resultRedirectFactory->create();
     $resultRedirect->setPath('sales/order_creditmemo/view', ['creditmemo_id' => $creditmemoId]);
     return $resultRedirect;
 }
Ejemplo n.º 26
0
 /**
  * Create product duplicate
  *
  * @return \Magento\Backend\Model\View\Result\Redirect
  */
 public function execute()
 {
     /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
     $resultRedirect = $this->resultRedirectFactory->create();
     $product = $this->productBuilder->build($this->getRequest());
     try {
         $newProduct = $this->productCopier->copy($product);
         $this->messageManager->addSuccess(__('You duplicated the product.'));
         $resultRedirect->setPath('catalog/*/edit', ['_current' => true, 'id' => $newProduct->getId()]);
     } catch (\Exception $e) {
         $this->_objectManager->get('Psr\\Log\\LoggerInterface')->critical($e);
         $this->messageManager->addError($e->getMessage());
         $resultRedirect->setPath('catalog/*/edit', ['_current' => true]);
     }
     return $resultRedirect;
 }
Ejemplo n.º 27
0
 /**
  * Saving edited user information
  *
  * @return \Magento\Backend\Model\View\Result\Redirect
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 public function execute()
 {
     $userId = $this->_objectManager->get('Magento\\Backend\\Model\\Auth\\Session')->getUser()->getId();
     $password = (string) $this->getRequest()->getParam('password');
     $passwordConfirmation = (string) $this->getRequest()->getParam('password_confirmation');
     $interfaceLocale = (string) $this->getRequest()->getParam('interface_locale', false);
     /** @var $user \Magento\User\Model\User */
     $user = $this->_objectManager->create('Magento\\User\\Model\\User')->load($userId);
     $user->setId($userId)->setUsername($this->getRequest()->getParam('username', false))->setFirstname($this->getRequest()->getParam('firstname', false))->setLastname($this->getRequest()->getParam('lastname', false))->setEmail(strtolower($this->getRequest()->getParam('email', false)));
     if ($this->_objectManager->get('Magento\\Framework\\Locale\\Validator')->isValid($interfaceLocale)) {
         $user->setInterfaceLocale($interfaceLocale);
         /** @var \Magento\Backend\Model\Locale\Manager $localeManager */
         $localeManager = $this->_objectManager->get('Magento\\Backend\\Model\\Locale\\Manager');
         $localeManager->switchBackendInterfaceLocale($interfaceLocale);
     }
     /** Before updating admin user data, ensure that password of current admin user is entered and is correct */
     $currentUserPasswordField = \Magento\User\Block\User\Edit\Tab\Main::CURRENT_USER_PASSWORD_FIELD;
     $currentUserPassword = $this->getRequest()->getParam($currentUserPasswordField);
     $isCurrentUserPasswordValid = !empty($currentUserPassword) && is_string($currentUserPassword);
     try {
         if (!($isCurrentUserPasswordValid && $user->verifyIdentity($currentUserPassword))) {
             throw new AuthenticationException(__('You have entered an invalid password for current user.'));
         }
         if ($password !== '') {
             $user->setPassword($password);
             $user->setPasswordConfirmation($passwordConfirmation);
         }
         $user->save();
         /** Send password reset email notification only when password was changed */
         if ($password !== '') {
             $user->sendPasswordResetNotificationEmail();
         }
         $this->messageManager->addSuccess(__('The account has been saved.'));
     } catch (\Magento\Framework\Validator\Exception $e) {
         $this->messageManager->addMessages($e->getMessages());
         if ($e->getMessage()) {
             $this->messageManager->addError($e->getMessage());
         }
     } catch (\Magento\Framework\Exception\LocalizedException $e) {
         $this->messageManager->addError($e->getMessage());
     } catch (\Exception $e) {
         $this->messageManager->addError(__('An error occurred while saving account.'));
     }
     /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
     $resultRedirect = $this->resultRedirectFactory->create();
     return $resultRedirect->setPath("*/*/");
 }
Ejemplo n.º 28
0
 /**
  * Download backup action
  *
  * @return void|\Magento\Backend\App\Action
  */
 public function execute()
 {
     /* @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;
 }
Ejemplo n.º 29
0
 /**
  * @return \Magento\Backend\Model\View\Result\Page
  */
 public function execute()
 {
     $this->_setTypeId();
     $attributeSet = $this->_objectManager->create('Magento\\Eav\\Model\\Entity\\Attribute\\Set')->load($this->getRequest()->getParam('id'));
     if (!$attributeSet->getId()) {
         return $this->resultRedirectFactory->create()->setPath('catalog/*/index');
     }
     $this->_coreRegistry->register('current_attribute_set', $attributeSet);
     /** @var \Magento\Backend\Model\View\Result\Page $resultPage */
     $resultPage = $this->resultPageFactory->create();
     $resultPage->setActiveMenu('Magento_Catalog::catalog_attributes_sets');
     $resultPage->getConfig()->getTitle()->prepend(__('Product Templates'));
     $resultPage->getConfig()->getTitle()->prepend($attributeSet->getId() ? $attributeSet->getAttributeSetName() : __('New Set'));
     $resultPage->addBreadcrumb(__('Catalog'), __('Catalog'));
     $resultPage->addBreadcrumb(__('Manage Product Sets'), __('Manage Product Sets'));
     return $resultPage;
 }
Ejemplo n.º 30
0
 protected function setUp()
 {
     $this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
     $this->messageManagerMock = $this->getMock('Magento\\Framework\\Message\\ManagerInterface', [], [], '', false);
     $this->requestMock = $this->getMockForAbstractClass('Magento\\Framework\\App\\RequestInterface', [], '', false, true, true, ['getParam']);
     $this->blockMock = $this->getMockBuilder('Magento\\Cms\\Model\\Block')->disableOriginalConstructor()->setMethods(['load', 'delete'])->getMock();
     $this->objectManagerMock = $this->getMockBuilder('Magento\\Framework\\ObjectManager\\ObjectManager')->disableOriginalConstructor()->setMethods(['create'])->getMock();
     $this->resultRedirectMock = $this->getMockBuilder('Magento\\Backend\\Model\\View\\Result\\Redirect')->setMethods(['setPath'])->disableOriginalConstructor()->getMock();
     $this->resultRedirectFactoryMock = $this->getMockBuilder('Magento\\Backend\\Model\\View\\Result\\RedirectFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock();
     $this->resultRedirectFactoryMock->expects($this->atLeastOnce())->method('create')->willReturn($this->resultRedirectMock);
     $this->contextMock = $this->getMock('\\Magento\\Backend\\App\\Action\\Context', [], [], '', false);
     $this->contextMock->expects($this->any())->method('getRequest')->willReturn($this->requestMock);
     $this->contextMock->expects($this->any())->method('getMessageManager')->willReturn($this->messageManagerMock);
     $this->contextMock->expects($this->any())->method('getObjectManager')->willReturn($this->objectManagerMock);
     $this->contextMock->expects($this->any())->method('getResultRedirectFactory')->willReturn($this->resultRedirectFactoryMock);
     $this->deleteController = $this->objectManager->getObject('Magento\\Cms\\Controller\\Adminhtml\\Block\\Delete', ['context' => $this->contextMock]);
 }