I have added a plugin which should be triggered when a coupon code is applied. Sadly nothing happens, no errors too.

Where did I go wrong?


namespace Zygis\TestModule\Plugin;

class CheckoutCouponApply {

    public function beforeSet(\Magento\Quote\Model\CouponManagement $subject, $cartId, $couponCode)
        $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
        $logger        = $objectManager->create('\Psr\Log\LoggerInterface');
        $logger->debug('test before set');

    public function afterSet(\Magento\Quote\Model\CouponManagement $subject, $cartId, $couponCode)
        $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
        $logger        = $objectManager->create('\Psr\Log\LoggerInterface');
        $logger->debug('test after set');

And obviously I got it registered in Zygis\TestModule\etc\frontend\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\Quote\Model\CouponManagement">
        <plugin name="CheckoutCouponApply" type="Zygis\TestModule\Plugin\CheckoutCouponApply" sortOrder="1" />

Any help is appreciated! Thanks!

  • Sadly you are on the wrong path for coupone code. What is your primary goal for plugin? – Keyur Shah Jul 28 '16 at 9:20
  • I want to change the error message for an expired coupon code later. However now I just want to see the plugin being fired. Please elaborate why I'm on the wrong path? – user3713377 Jul 28 '16 at 9:25
  • I have found the right way. I created a preference instead of plugin. – user3713377 Jul 28 '16 at 12:44
  • Did you found the solution using plugin way? – Chirag Patel Jul 8 '19 at 6:11

If anybody stumbles across this in the future, make sure your di.xml file for the REST endpoints resides in the etc directory, not the etc/frontend directory.





| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.