php Magento-Backend-Model-View-Result-ForwardFactory类(方法)实例源码

下面列出了php Magento-Backend-Model-View-Result-ForwardFactory 类(方法)源码代码实例,从而了解它的用法。

作者:BlackIkeEagl    项目:magento2-continuousph   
/**
  * 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;
     }
 }

作者:shabbirvividad    项目:magento   
/**
  * 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;
     }
 }

作者:mageplaz    项目:magento-2-blog-extensio   
/**
  * 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;
 }

作者:rafaelst    项目:magento   
/**
  * 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;
 }

作者:nblai    项目:magescotc   
/**
  * @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;
     }
 }

作者:nblai    项目:magescotc   
/**
  * 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;
     }
 }

作者:nblai    项目:magescotc   
/**
  * @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');
     }
 }

作者:nblai    项目:magescotc   
/**
  * 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');
 }

作者:BlackIkeEagl    项目:magento2-continuousph   
/**
  * 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;
 }

作者:pradeep-wagent    项目:magento   
/**
  * 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');
     }
 }

作者:nblai    项目:magescotc   
/**
  * 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;
 }

作者:shabbirvividad    项目:magento   
/**
  * @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');
     }
 }

作者:opexs    项目:magento   
/**
  * 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]);
 }

作者:kidaa3    项目:magento2-platforms   
/**
  * 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]);
 }

作者:nblai    项目:magescotc   
/**
     * @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());
    }

作者:kidaa3    项目:magento2-platforms   
/**
  * @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());
 }

作者:nblai    项目:magescotc   
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());
    }

作者:pradeep-wagent    项目:magento   
/**
  * @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());
 }

作者:Doabilit    项目:magento2de   
/**
  * @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());
 }

作者:Doabilit    项目:magento2de   
/**
  * @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());
 }


问题


面经


文章

微信
公众号

扫码关注公众号