Event change price in cart Magento

magento

In Magento, event been used a lot. Event in Magento is very strong.

If you want change price in cart of Magento, but not is add product to cart. Simple, let’s using event..

Following, I will create demo a event:

  • Initialization event in config.xml
  • Using event name: sales_quote_add_item
  • Using function: updateProductCartPrice

 

<frontend>

        <events>

            <!--event when addto cart-->

            <sales_quote_add_item>

                <observers>

                    <Test_ Addcart >

                        <type>singleton</type>

                        <class>Test_Addcart _Model_Observers</class>

                        <method>updateProductCartPrice</method>

                    </Test_Addcart>

                </observers>

            </sales_quote_add_item>

        </event>

    </frontend>

 

In Observers.php file. My url: app/code/local/Test/Addcart/Model/Observers.php

Create a function updateProductCartPrice have content:

  • priceChange: new price

 

public function updateProductCartPrice($observer)

    {

        $item           = $observer->getQuoteItem();

        $pro                               = ( $item->getParentItem() ? $item->getParentItem() : $item );

        $priceChange            = 3500;

        $pro->setCustomPrice($priceChange);

        $pro->setOriginalCustomPrice($priceChange);

    }

 

Ok. So, price will change in cart after load again page.

event-change-price-magento