Question

I'm using Magento 2.3.4 , i tried to create a plugin for add to wishlist controller like this:

app/code/Vendor/All/etc/di.xml

<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Wishlist\Controller\Index\Add">
        <plugin disabled="false" name="Vendor_All_Plugin_Magento_Wishlist_Controller_Index_Add" sortOrder="10" type="Vendor\All\Plugin\Magento\Wishlist\Controller\Index\Add"/>
    </type>
</config>

app/code/Vendor/All/Plugin/Magento/Wishlist/Controller/Index/Add.php

namespace Vendor\All\Plugin\Magento\Wishlist\Controller\Index;

class Add
{
    public function beforeExecute(
        \Magento\Wishlist\Controller\Index\Add $subject
    ) {
       die('success');
    }
}

when i access this controller, the die function is not working and still doing the normal controller function

Was it helpful?

Solution

You code seem well. Check comoposer.json.registration.php,etc/modules.xmlexits at on your module. This minimum files to create a module.

Also, check your module is enabled/not and checkout at app/etc/config.php.If it is not enabled then you need to enable module do setup upgrade, di compile

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top