Magento 2加入愿望清单返回产品详细信息页面

时间:2016-11-18 03:14:21

标签: magento magento2

目前在Magento 2中将产品添加到愿望清单后,它将移至愿望清单页面。我正在尝试将其移回产品详细信息页面。所以对于它我试图覆盖Magento \ Wishlist \ Controller \ Index \ Add with di preference

<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模块控制器。能不能让我知道我的压倒过程有什么问题吗?非常感谢你。

2 个答案:

答案 0 :(得分:0)

在Magento2 Magento \ Wishlist \ Controller \ Index \ Add被另一个核心模块MultipleWishlist模块Magento \ MultipleWishlist \ Controller \ Index \覆盖,所以如果你想覆盖wishlist添加控制器,那么你应该覆盖MultipleWishlist添加控制器。

我希望它对您有用,并且可以节省您的时间。

答案 1 :(得分:0)

感谢阿巴斯

在模块di.xml中

c.title = data[“title”]

注意:在MultipleWhislist的覆盖控制器中

   <?xml version="1.0"?>
 <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd">        
    <preference for="Magento\MultipleWishlist\Controller\Index\Add" type="Vendor\Module\Controller\MultipleWishlist\Add" />
    <preference for="Magento\Wishlist\Controller\Index\Add" type="Vendor\Module\Controller\Wishlist\Add" />
</config>

一切正常。