/** * Creditmemo create page * * @return \Magento\Backend\Model\View\Result\Page|\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) { if ($comment = $this->_objectManager->get('Magento\\Backend\\Model\\Session')->getCommentText(true)) { $creditmemo->setCommentText($comment); } $resultPage = $this->resultPageFactory->create(); $resultPage->setActiveMenu('Magento_Sales::sales_order'); $resultPage->getConfig()->getTitle()->prepend(__('Credit Memos')); if ($creditmemo->getInvoice()) { $resultPage->getConfig()->getTitle()->prepend(__("New Memo for #%1", $creditmemo->getInvoice()->getIncrementId())); } else { $resultPage->getConfig()->getTitle()->prepend(__("New Memo")); } return $resultPage; } else { $resultForward = $this->resultForwardFactory->create(); $resultForward->forward('noroute'); return $resultForward; } }
/** * 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; } }
/** * forward to edit * * @return \Magento\Backend\Model\View\Result\Forward */ public function execute() { $this->_getSession()->unsMageplazaBlogCategoryActiveTabId(); $resultForward = $this->resultForwardFactory->create(); $resultForward->forward('edit'); return $resultForward; }
/** * Create new product page * * @return \Magento\Framework\Controller\ResultInterface */ public function execute() { if (!$this->getRequest()->getParam('set')) { return $this->resultForwardFactory->create()->forward('noroute'); } $product = $this->productBuilder->build($this->getRequest()); $productData = $this->getRequest()->getPost('product'); if (!$productData) { $sessionData = $this->_session->getProductData(true); if (!empty($sessionData['product'])) { $productData = $sessionData['product']; } } if ($productData) { $stockData = isset($productData['stock_data']) ? $productData['stock_data'] : []; $productData['stock_data'] = $this->stockFilter->filter($stockData); $product = $this->getInitializationHelper()->initializeFromData($product, $productData); } $this->_eventManager->dispatch('catalog_product_new_action', ['product' => $product]); /** @var \Magento\Backend\Model\View\Result\Page $resultPage */ $resultPage = $this->resultPageFactory->create(); if ($this->getRequest()->getParam('popup')) { $resultPage->addHandle(['popup', 'catalog_product_' . $product->getTypeId()]); } else { $resultPage->addHandle(['catalog_product_' . $product->getTypeId()]); $resultPage->setActiveMenu('Magento_Catalog::catalog_products'); $resultPage->getConfig()->getTitle()->prepend(__('Products')); $resultPage->getConfig()->getTitle()->prepend(__('New Product')); } $block = $resultPage->getLayout()->getBlock('catalog.wysiwyg.js'); if ($block) { $block->setStoreId($product->getStoreId()); } return $resultPage; }
/** * @return ResponseInterface|\Magento\Backend\Model\View\Result\Forward */ public function executeInternal() { /** @see \Magento\Sales\Controller\Adminhtml\Order\Invoice */ $creditmemoId = $this->getRequest()->getParam('creditmemo_id'); if ($creditmemoId) { $creditmemo = $this->creditmemoRepository->get($creditmemoId); if ($creditmemo) { $pdf = $this->_objectManager->create( 'Magento\Sales\Model\Order\Pdf\Creditmemo' )->getPdf( [$creditmemo] ); $date = $this->_objectManager->get('Magento\Framework\Stdlib\DateTime\DateTime')->date('Y-m-d_H-i-s'); return $this->_fileFactory->create( 'creditmemo' . $date . '.pdf', $pdf->render(), DirectoryList::VAR_DIR, 'application/pdf' ); } } else { $resultForward = $this->resultForwardFactory->create(); $resultForward->forward('noroute'); return $resultForward; } }
/** * Creditmemo information page * * @return \Magento\Backend\Model\View\Result\Page|\Magento\Backend\Model\View\Result\Forward */ public function executeInternal() { $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) { $resultPage = $this->resultPageFactory->create(); $resultPage->getLayout()->getBlock('sales_creditmemo_view') ->updateBackButtonUrl($this->getRequest()->getParam('come_from')); $resultPage->setActiveMenu('Magento_Sales::sales_creditmemo'); if ($creditmemo->getInvoice()) { $resultPage->getConfig()->getTitle()->prepend( __("View Memo for #%1", $creditmemo->getInvoice()->getIncrementId()) ); } else { $resultPage->getConfig()->getTitle()->prepend(__("View Memo")); } return $resultPage; } else { $resultForward = $this->resultForwardFactory->create(); $resultForward->forward('noroute'); return $resultForward; } }
/** * @return ResponseInterface|\Magento\Backend\Model\View\Result\Forward */ public function executeInternal() { $shipmentId = $this->getRequest()->getParam('shipment_id'); if ($shipmentId) { $shipment = $this->_objectManager->create('Magento\Sales\Model\Order\Shipment')->load($shipmentId); if ($shipment) { $pdf = $this->_objectManager->create( 'Magento\Sales\Model\Order\Pdf\Shipment' )->getPdf( [$shipment] ); $date = $this->_objectManager->get('Magento\Framework\Stdlib\DateTime\DateTime')->date('Y-m-d_H-i-s'); return $this->_fileFactory->create( 'packingslip' . $date . '.pdf', $pdf->render(), DirectoryList::VAR_DIR, 'application/pdf' ); } } else { /** @var \Magento\Backend\Model\View\Result\Forward $resultForward */ $resultForward = $this->resultForwardFactory->create(); return $resultForward->forward('noroute'); } }
/** * Add new category form * * @return \Magento\Backend\Model\View\Result\Forward */ public function executeInternal() { $this->_objectManager->get('Magento\\Backend\\Model\\Auth\\Session')->unsActiveTabId(); /** @var \Magento\Backend\Model\View\Result\Forward $resultForward */ $resultForward = $this->resultForwardFactory->create(); return $resultForward->forward('edit'); }
/** * Invoice information page * * @return \Magento\Backend\Model\View\Result\Forward */ public function execute() { $resultForward = $this->resultForwardFactory->create(); if ($this->getRequest()->getParam('invoice_id')) { $resultForward->setController('order_invoice')->setParams(['come_from' => 'invoice'])->forward('view'); } else { $resultForward->forward('noroute'); } return $resultForward; }
/** * Shipment information page * * @return \Magento\Backend\Model\View\Result\Forward */ public function execute() { /** @var \Magento\Backend\Model\View\Result\Forward $resultForward */ $resultForward = $this->resultForwardFactory->create(); if ($this->getRequest()->getParam('shipment_id')) { $resultForward->setController('order_shipment')->setModule('admin')->setParams(['come_from' => 'shipment'])->forward('view'); return $resultForward; } else { return $resultForward->forward('noroute'); } }
/** * Creditmemo information page * * @return \Magento\Backend\Model\View\Result\Forward */ public function executeInternal() { $resultForward = $this->resultForwardFactory->create(); if ($this->getRequest()->getParam('creditmemo_id')) { $resultForward->setController('order_creditmemo'); $resultForward->setParams(['come_from' => 'sales_creditmemo']); $resultForward->forward('view'); } else { $resultForward->forward('noroute'); } return $resultForward; }
/** * @return ResponseInterface|void */ public function execute() { $invoiceId = $this->getRequest()->getParam('invoice_id'); if ($invoiceId) { $invoice = $this->_objectManager->create('Magento\\Sales\\Model\\Order\\Invoice')->load($invoiceId); if ($invoice) { $pdf = $this->_objectManager->create('Magento\\Sales\\Model\\Order\\Pdf\\Invoice')->getPdf([$invoice]); $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'); } } else { return $this->resultForwardFactory->create()->forward('noroute'); } }
/** * 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]); }
/** * 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\\Api\\InvoiceRepositoryInterface')->get($invoiceId); if (!$invoice) { return $this->resultForwardFactory->create()->forward('noroute'); } $this->_objectManager->create('Magento\\Sales\\Api\\InvoiceManagementInterface')->notify($invoice->getEntityId()); $this->messageManager->addSuccess(__('You sent the message.')); return $this->resultRedirectFactory->create()->setPath('sales/invoice/view', ['order_id' => $invoice->getOrder()->getId(), 'invoice_id' => $invoiceId]); }
/** * @return void */ public function testExecuteNoInvoice() { $invoiceId = 2; $this->requestMock->expects($this->once()) ->method('getParam') ->with('invoice_id') ->will($this->returnValue($invoiceId)); $invoiceRepository = $this->getMockBuilder('Magento\Sales\Api\InvoiceRepositoryInterface') ->disableOriginalConstructor() ->getMock(); $invoiceRepository->expects($this->any()) ->method('get') ->willReturn(null); $this->objectManagerMock->expects($this->once()) ->method('create') ->with('Magento\Sales\Api\InvoiceRepositoryInterface') ->willReturn($invoiceRepository); $resultForward = $this->getMockBuilder('Magento\Backend\Model\View\Result\Forward') ->disableOriginalConstructor() ->getMock(); $resultForward->expects($this->once())->method('forward')->with(('noroute'))->will($this->returnSelf()); $this->resultForwardFactoryMock->expects($this->once()) ->method('create') ->will($this->returnValue($resultForward)); $this->assertSame($resultForward, $this->controller->executeInternal()); }
/** * @return void */ public function testExecuteNoCreditmemo() { $this->requestMock->expects($this->once())->method('getParam')->with('creditmemo_id')->willReturn(null); $this->resultForwardFactoryMock->expects($this->once())->method('create')->willReturn($this->resultForwardMock); $this->resultForwardMock->expects($this->once())->method('forward')->with('noroute')->willReturnSelf(); $this->assertInstanceOf('Magento\\Backend\\Model\\View\\Result\\Forward', $this->controller->execute()); }
public function testExecuteWithoutTaxClass() { $this->request->expects($this->once())->method('getParam')->with('tax_class')->willReturn(null); $this->forwardFactoryMock->expects($this->once())->method('create')->willReturn($this->resultForward); $this->resultForward->expects($this->once())->method('forward')->with('new')->willReturnSelf(); $this->assertSame($this->resultForward, $this->controller->execute()); }
public function testEmailNoInvoice() { $invoiceId = 10000031; $this->request->expects($this->once()) ->method('getParam') ->with('invoice_id') ->willReturn($invoiceId); $invoiceRepository = $this->getMockBuilder('Magento\Sales\Api\InvoiceRepositoryInterface') ->disableOriginalConstructor() ->getMock(); $invoiceRepository->expects($this->any()) ->method('get') ->willReturn(null); $this->objectManager->expects($this->at(0)) ->method('create') ->with('Magento\Sales\Api\InvoiceRepositoryInterface') ->willReturn($invoiceRepository); $this->resultForwardFactory->expects($this->any()) ->method('create') ->willReturn($this->resultForward); $this->resultForward->expects($this->once()) ->method('forward') ->with('noroute') ->willReturnSelf(); $this->assertInstanceOf('Magento\Backend\Model\View\Result\Forward', $this->invoiceEmail->executeInternal()); }
/** * @covers \Magento\Sales\Controller\Adminhtml\Order\Creditmemo\PrintAction::execute */ public function testExecuteNoCreditmemoId() { $this->prepareTestExecute(); $this->resultForwardFactoryMock->expects($this->once())->method('create')->willReturn($this->resultForwardMock); $this->resultForwardMock->expects($this->once())->method('forward')->with('noroute')->willReturnSelf(); $this->assertInstanceOf('Magento\\Backend\\Model\\View\\Result\\Forward', $this->printAction->execute()); }
/** * @covers \Magento\Customer\Controller\Adminhtml\Index\Index::execute */ public function testExecuteAjax() { $this->prepareExecute(true); $this->resultForwardFactoryMock->expects($this->once())->method('create')->willReturn($this->resultForwardMock); $this->resultForwardMock->expects($this->once())->method('forward')->with('grid')->willReturnSelf(); $this->assertInstanceOf('Magento\\Backend\\Model\\View\\Result\\Forward', $this->indexController->execute()); }
/** * @return void */ public function testExecuteNoInvoice() { $invoiceId = 2; $this->requestMock->expects($this->once())->method('getParam')->with('invoice_id')->will($this->returnValue($invoiceId)); $this->invoiceRepository->expects($this->once())->method('get')->willReturn(null); $resultForward = $this->getMockBuilder('Magento\\Backend\\Model\\View\\Result\\Forward')->disableOriginalConstructor()->setMethods([])->getMock(); $resultForward->expects($this->once())->method('forward')->with('noroute')->will($this->returnSelf()); $this->resultForwardFactoryMock->expects($this->once())->method('create')->will($this->returnValue($resultForward)); $this->assertSame($resultForward, $this->controller->execute()); }
/** * Run test execute method (no shipment) */ public function testExecuteNoShipment() { $orderId = 1; $shipmentId = 1; $shipment = []; $tracking = []; $this->loadShipment($orderId, $shipmentId, $shipment, $tracking, null, false); $this->resultForwardFactoryMock->expects($this->once())->method('create')->willReturn($this->resultForwardMock); $this->resultForwardMock->expects($this->once())->method('forward')->with('noroute')->willReturnSelf(); $this->assertEquals($this->resultForwardMock, $this->controller->execute()); }
/** * Shipment information page * * @return void */ public function execute() { $this->shipmentLoader->setOrderId($this->getRequest()->getParam('order_id')); $this->shipmentLoader->setShipmentId($this->getRequest()->getParam('shipment_id')); $this->shipmentLoader->setShipment($this->getRequest()->getParam('shipment')); $this->shipmentLoader->setTracking($this->getRequest()->getParam('tracking')); $shipment = $this->shipmentLoader->load(); if ($shipment) { $resultPage = $this->resultPageFactory->create(); $resultPage->getLayout()->getBlock('sales_shipment_view')->updateBackButtonUrl($this->getRequest()->getParam('come_from')); $resultPage->setActiveMenu('Magento_Sales::sales_shipment'); $resultPage->getConfig()->getTitle()->prepend(__('Shipments')); $resultPage->getConfig()->getTitle()->prepend("#" . $shipment->getIncrementId()); return $resultPage; } else { $resultForward = $this->resultForwardFactory->create(); $resultForward->forward('noroute'); return $resultForward; } }
public function testEmailNoInvoice() { $invoiceId = 10000031; $invoiceClassName = 'Magento\\Sales\\Model\\Order\\Invoice'; $invoice = $this->getMock($invoiceClassName, [], [], '', false); $this->request->expects($this->once())->method('getParam')->with('invoice_id')->willReturn($invoiceId); $this->objectManager->expects($this->at(0))->method('create')->with($invoiceClassName)->willReturn($invoice); $invoice->expects($this->once())->method('load')->with($invoiceId)->willReturn(null); $this->resultForwardFactory->expects($this->any())->method('create')->willReturn($this->resultForward); $this->resultForward->expects($this->once())->method('forward')->with('noroute')->willReturnSelf(); $this->assertInstanceOf('Magento\\Backend\\Model\\View\\Result\\Forward', $this->invoiceEmail->execute()); }
/** * Save creditmemo * We can save only new creditmemo. Existing creditmemos are not editable * * @return \Magento\Backend\Model\View\Result\Redirect|\Magento\Backend\Model\View\Result\Forward * * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) */ public function execute() { $resultRedirect = $this->resultRedirectFactory->create(); $data = $this->getRequest()->getPost('creditmemo'); if (!empty($data['comment_text'])) { $this->_getSession()->setCommentText($data['comment_text']); } 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')); $creditmemo = $this->creditmemoLoader->load(); if ($creditmemo) { if (!$creditmemo->isValidGrandTotal()) { throw new \Magento\Framework\Exception\LocalizedException(__('The credit memo\'s total must be positive.')); } if (!empty($data['comment_text'])) { $creditmemo->addComment($data['comment_text'], isset($data['comment_customer_notify']), isset($data['is_visible_on_front'])); $creditmemo->setCustomerNote($data['comment_text']); $creditmemo->setCustomerNoteNotify(isset($data['comment_customer_notify'])); } if (isset($data['do_offline'])) { //do not allow online refund for Refund to Store Credit if (!$data['do_offline'] && !empty($data['refund_customerbalance_return_enable'])) { throw new \Magento\Framework\Exception\LocalizedException(__('Cannot create online refund for Refund to Store Credit.')); } } $creditmemoManagement = $this->_objectManager->create('Magento\\Sales\\Api\\CreditmemoManagementInterface'); $creditmemoManagement->refund($creditmemo, (bool) $data['do_offline'], !empty($data['send_email'])); if (!empty($data['send_email'])) { $this->creditmemoSender->send($creditmemo); } $this->messageManager->addSuccess(__('You created the credit memo.')); $this->_getSession()->getCommentText(true); $resultRedirect->setPath('sales/order/view', ['order_id' => $creditmemo->getOrderId()]); return $resultRedirect; } else { $resultForward = $this->resultForwardFactory->create(); $resultForward->forward('noroute'); return $resultForward; } } catch (\Magento\Framework\Exception\LocalizedException $e) { $this->messageManager->addError($e->getMessage()); $this->_getSession()->setFormData($data); } catch (\Exception $e) { $this->_objectManager->get('Psr\\Log\\LoggerInterface')->critical($e); $this->messageManager->addError(__('We can\'t save the credit memo right now.')); } $resultRedirect->setPath('sales/*/new', ['_current' => true]); return $resultRedirect; }
protected function setUp() { $objectManagerHelper = new ObjectManagerHelper($this); $context = $this->getMock('Magento\\Backend\\App\\Action\\Context', [], [], '', false); $this->request = $this->getMockForAbstractClass('Magento\\Framework\\App\\RequestInterface', [], '', false, true, true, ['getParam', 'getPost', 'getPostValue', 'get', 'has', 'setModuleName', 'setActionName', 'initForward', 'setDispatched', 'getModuleName', 'getActionName', 'getCookie']); $response = $this->getMockForAbstractClass('Magento\\Framework\\App\\ResponseInterface', [], '', false, true, true, []); $context->expects($this->any())->method('getResponse')->willReturn($response); $context->expects($this->any())->method('getRequest')->willReturn($this->request); $this->messageManager = $this->getMock('Magento\\Framework\\Message\\ManagerInterface', [], [], '', false); $context->expects($this->any())->method('getMessageManager')->willReturn($this->messageManager); $this->eventManager = $this->getMock('Magento\\Framework\\Event\\ManagerInterface', [], [], '', false); $context->expects($this->any())->method('getEventManager')->willReturn($this->eventManager); $this->objectManager = $this->getMock('Magento\\Framework\\ObjectManagerInterface'); $context->expects($this->any())->method('getObjectManager')->willReturn($this->objectManager); $this->session = $this->getMock('Magento\\Backend\\Model\\Session\\Quote', [], [], '', false); $context->expects($this->any())->method('getSession')->willReturn($this->session); $this->escaper = $this->getMock('Magento\\Framework\\Escaper', ['escapeHtml'], [], '', false); $this->resultForward = $this->getMockBuilder('Magento\\Backend\\Model\\View\\Result\\Forward')->disableOriginalConstructor()->getMock(); $this->resultForwardFactory = $this->getMockBuilder('Magento\\Backend\\Model\\View\\Result\\ForwardFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock(); $this->resultForwardFactory->expects($this->once())->method('create')->willReturn($this->resultForward); $this->processData = $objectManagerHelper->getObject('Magento\\Sales\\Controller\\Adminhtml\\Order\\Create\\ProcessData', ['context' => $context, 'escaper' => $this->escaper, 'resultForwardFactory' => $this->resultForwardFactory]); }
/** * Cancel creditmemo action * * @return \Magento\Backend\Model\View\Result\Redirect|\Magento\Backend\Model\View\Result\Forward */ public function execute() { $creditmemoId = $this->getRequest()->getParam('creditmemo_id'); if ($creditmemoId) { try { $creditmemoManagement = $this->_objectManager->create('Magento\\Sales\\Api\\CreditmemoManagementInterface'); $creditmemoManagement->cancel($creditmemoId); $this->messageManager->addSuccess(__('The credit memo has been canceled.')); } catch (\Magento\Framework\Exception\LocalizedException $e) { $this->messageManager->addError($e->getMessage()); } catch (\Exception $e) { $this->messageManager->addError(__('Credit memo has not been canceled.')); } $resultRedirect = $this->resultRedirectFactory->create(); $resultRedirect->setPath('sales/*/view', ['creditmemo_id' => $creditmemoId]); return $resultRedirect; } else { $resultForward = $this->resultForwardFactory->create(); $resultForward->forward('noroute'); return $resultForward; } }
/** * Create new product page * * @return \Magento\Framework\Controller\ResultInterface */ public function execute() { if (!$this->getRequest()->getParam('set')) { return $this->resultForwardFactory->create()->forward('noroute'); } $product = $this->productBuilder->build($this->getRequest()); $this->_eventManager->dispatch('catalog_product_new_action', ['product' => $product]); /** @var \Magento\Backend\Model\View\Result\Page $resultPage */ $resultPage = $this->resultPageFactory->create(); if ($this->getRequest()->getParam('popup')) { $resultPage->addHandle(['popup', 'catalog_product_' . $product->getTypeId()]); } else { $resultPage->addHandle(['catalog_product_' . $product->getTypeId()]); $resultPage->setActiveMenu('Magento_Catalog::catalog_products'); $resultPage->getConfig()->getTitle()->prepend(__('Products')); $resultPage->getConfig()->getTitle()->prepend(__('New Product')); } $block = $resultPage->getLayout()->getBlock('catalog.wysiwyg.js'); if ($block) { $block->setStoreId($product->getStoreId()); } return $resultPage; }
/** * @return void */ public function testExecuteNoInvoice() { $invoiceId = 2; $this->requestMock->expects($this->once())->method('getParam')->with('invoice_id')->will($this->returnValue($invoiceId)); $invoiceMock = $this->getMockBuilder('Magento\\Sales\\Model\\Order\\Invoice')->disableOriginalConstructor()->setMethods([])->getMock(); $invoiceMock->expects($this->once())->method('load')->willReturn(null); $this->objectManagerMock->expects($this->once())->method('create')->with('Magento\\Sales\\Model\\Order\\Invoice')->willReturn($invoiceMock); $this->messageManagerMock->expects($this->never())->method('addError'); $this->messageManagerMock->expects($this->never())->method('addSuccess'); $resultForward = $this->getMockBuilder('Magento\\Backend\\Model\\View\\Result\\Forward')->disableOriginalConstructor()->setMethods([])->getMock(); $resultForward->expects($this->once())->method('forward')->with('noroute')->will($this->returnSelf()); $this->resultForwardFactoryMock->expects($this->once())->method('create')->will($this->returnValue($resultForward)); $this->assertSame($resultForward, $this->controller->execute()); }
/** * @return void */ public function testExecuteNoCreditmemo() { $this->requestMock->expects($this->any()) ->method('getParam') ->withAnyParameters() ->willReturnArgument(0); $this->loaderMock->expects($this->once()) ->method('load') ->willReturn(false); $this->resultForwardFactoryMock->expects($this->once()) ->method('create') ->willReturn($this->resultForwardMock); $this->resultForwardMock->expects($this->once()) ->method('forward') ->with('noroute') ->willReturnSelf(); $this->assertInstanceOf( 'Magento\Backend\Model\View\Result\Forward', $this->controller->executeInternal() ); }