1

I have created add to cart before the event it's working fine. But I want to the observer after add to cart please tell me how to do it.

<?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="controller_action_predispatch_checkout_cart_add">
        <observer name="cart_eventbefore_observer_cartbefore" instance="Cart\Eventbefore\Observer\Cartbefore" />
    </event>
</config>

2 Answers 2

9

You can use the checkout_cart_add_product_complete event, which fires after the product added to cart successfully.

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_add_product_complete"> 
      <observer name="after_add_to_cart" instance="YourObserverFile" /> 
   </event>
</config>
0
6

checkout_cart_product_add_after worked for me.

Here are the events fired for checkout cart:

checkout_cart_add_product_complete
checkout_cart_update_item_complete
checkout_cart_product_add_after
checkout_cart_update_items_before
checkout_cart_update_items_after
checkout_cart_save_before
checkout_cart_save_after
checkout_cart_product_update_after

https://cyrillschumacher.com/magento-2.2-list-of-all-dispatched-events/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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