2016-11-18 90 views
0

目前在Magento 2中,将产品添加到意愿清单之后,它将移动到意愿清单页面。我正试图将其移回产品详细信息页面。因此,对于它,我试图重写Magento的\收藏\控制器\首页\添加与迪偏好Magento 2追加到意愿清单返回到产品详细信息页面

<preference for="Magento\Wishlist\Controller\Index\Add" 
      type="Eguana\CustomWishlist\Controller\Rewrite\Index\Add" /> 

并为它我的控制器是这样

namespace Eguana\CustomWishlist\Controller\Rewrite\Index; 

use Magento\Catalog\Api\ProductRepositoryInterface; 
use Magento\Framework\App\Action; 
use Magento\Framework\Data\Form\FormKey\Validator; 
use Magento\Framework\Exception\NotFoundException; 
use Magento\Framework\Exception\NoSuchEntityException; 
use Magento\Framework\Controller\ResultFactory; 

/** 
* @SuppressWarnings(PHPMD.CouplingBetweenObjects) 
*/ 
class Add extends \Magento\Wishlist\Controller\Index\Add 
{ 


    public function __construct(Action\Context $context, \Magento\Customer\Model\Session $customerSession, \Magento\Wishlist\Controller\WishlistProviderInterface $wishlistProvider, ProductRepositoryInterface $productRepository, Validator $formKeyValidator) 
    { 
     parent::__construct($context, $customerSession, $wishlistProvider, $productRepository, $formKeyValidator); 
    } 

    /** 
    * Adding new item 
    * 
    * @return \Magento\Framework\Controller\Result\Redirect 
    * @throws NotFoundException 
    * @SuppressWarnings(PHPMD.CyclomaticComplexity) 
    * @SuppressWarnings(PHPMD.NPathComplexity) 
    * @SuppressWarnings(PHPMD.UnusedLocalVariable) 
    */ 
    public function execute() 
    { 
     echo 'abc'; 
    } 
} 

我的module.xml文件是这样的

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd"> 
    <module name="Eguana_CustomWishlist" setup_version="2.1.3"> 
     <sequence> 
      <module name="Magento_Wishlist" /> 
     </sequence> 
    </module> 
</config> 

但它仍在调用Magento Wishlist模块控制器。你能否让我知道我的压倒一切的过程中是否有任何问题?非常感谢你。

回答

0

在Magento2 Magento \ Wishlist \ Controller \ Index \ Add被另一个核心模块MultipleWishlist模块Magento \ MultipleWishlist \ Controller \ Index \覆盖。如果你想重载愿望清单添加控制器,那么你应该重写MultipleWishlist添加控制器。

我希望它能为你工作并节省你的时间。

相关问题