Event for Cart Update – Magento 1.9

cartevent-observermagento-1.9

I need to create a dynamic shopping cart rule depending on the count of items in the cart.

So I need to listen to an event which changes the item count in the cart (add product, remove product, change quantity).

Does such an event exist or do I have to listen for multiple events?

Best Answer

you can use this observer, it will be triggered whenever the cart is updated.

checkout_cart_save_after

magento_root/app/etc/modules/Namespace_Module.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Namespace_Module>
            <active>true</active>
            <codePool>local</codePool>
        </Namespace_Module>
    </modules>
</config>

magento_root/app/code/local/Namespace/Module/etc/config.xml

<?xml version="1.0"?> 
<config>
    <modules>
        <Namespace_Module>
            <version>0.1</version>
        </Namespace_Module>
    </modules>
    <global>
        <models>
            <namespace_module>
                <class>Namespace_Module_Model</class>
            </namespace_module>
        </models>   
        <events>
            <checkout_cart_save_after>
                <observers>
                    <cart_update>
                        <class>Namespace_Module_Model_UpdateObserver</class>
                        <method>updateCartAfter</method>
                    </cart_update>
                </observers>
            </checkout_cart_save_after>    
        </events>
    </global>
</config>

magento_root/app/code/local/Namespace/Module/Model/UpdateObserver.php

<?php

class Namespace_Module_Model_UpdateObserver {

    public function updateCartAfter($observer) {
        die('product add after');   
    }

}
Related Topic