Tuesday, 18 August 2015

After add to cart event magento


After add to cart event magento

Sometime we want to give discount after add to cart product or unset/set session after add to cart product for this situation i have created a small script.

Put below code in your module/any module config.xml file after <models> block
<global>
    <events>
        <checkout_cart_product_add_after>
            <observers>
                <Setblue_Banner_Model_Observer>
                    <type>singleton</type>
                    <class>Setblue_Banner_Model_Observer</class>
                    <method>addtocartEvent</method>
                </Setblue_Banner_Model_Observer>
            </observers>
        </checkout_cart_product_add_after>
    </events>
</global>

Next we need to create observer file to read this code. Create Observer.php in /yourmodule/Model/Observer.php and put the below code :

class Setblue_Banner_Model_Observer
{
    public function addtocartEvent(Varien_Event_Observer $observer) {

        // Do something here
        //unset($_SESSION['stitch5']);
/*$event = $observer->getEvent();  //Gets the event
        $product = $event->getProduct();
        $observermsg = "The product added successfully";
        //Adds the message to the shopping cart
        echo Mage::getSingleton('checkout/session')->addSuccess($observermsg);*/
    }

}

No comments: