3

Magento 2: Same Event with Multiple Observer in Different Module causes redirection issue

To solve: Magento 2: Can we call one observer in another observer?

I have followed below code

magento\app\code\Custom\Second\etc\module.xml

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

magento\app\code\Custom\First\etc\frontend\events.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
    <event name="checkout_cart_product_add_after">
        <observer name="first" instance="Custom\First\Observer\FirstObserver" />
    </event>
</config>

magento\app\code\Custom\Second\etc\frontend\events.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
    <event name="checkout_cart_product_add_after">
        <observer name="second" instance="Custom\Second\Observer\SecondObserver" />
    </event>
</config>

My second observer is & causing issue :- Magento 2: Observer not redirecting to checkout page

Your Answer

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

Browse other questions tagged or ask your own question.