当前位置: 首页>>代码示例>>PHP>>正文


PHP Result\RedirectFactory类代码示例

本文整理汇总了PHP中Magento\Backend\Model\View\Result\RedirectFactory的典型用法代码示例。如果您正苦于以下问题:PHP RedirectFactory类的具体用法?PHP RedirectFactory怎么用?PHP RedirectFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了RedirectFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: _redirectToOrder

 /**
  * 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;
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:13,代码来源:NewAction.php

示例2: execute

 /**
  * 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;
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:36,代码来源:Edit.php

示例3: execute

 /**
  * 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;
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:31,代码来源:Edit.php

示例4: execute

 /**
  * 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('*/*/');
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:37,代码来源:Delete.php

示例5: execute

 /**
  * 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;
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:66,代码来源:Save.php

示例6: execute

 /**
  * 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;
     }
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:37,代码来源:Void.php

示例7: execute

 /**
  * @return \Magento\Framework\Controller\ResultInterface
  */
 public function execute()
 {
     if (!$this->_validateProducts()) {
         return $this->resultRedirectFactory->create()->setPath('catalog/product/', ['_current' => true]);
     }
     return $this->resultPageFactory->create();
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:10,代码来源:Edit.php

示例8: setUp

 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]);
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:27,代码来源:ValidateTest.php

示例9: execute

 /**
  * 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/*/');
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:32,代码来源:AssignPost.php

示例10: setUp

 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]);
 }
开发者ID:opexsw,项目名称:magento2,代码行数:25,代码来源:EmailTest.php

示例11: execute

 /**
  * 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());
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:13,代码来源:Logout.php

示例12: testExecute

 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());
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:9,代码来源:RefreshStatisticsTest.php

示例13: execute

 /**
  * 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;
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:14,代码来源:Start.php

示例14: testEditActionBlockNoExists

 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());
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:11,代码来源:EditTest.php

示例15: setUp

 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]);
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:11,代码来源:SaveTest.php


注:本文中的Magento\Backend\Model\View\Result\RedirectFactory类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。