1

I want to add a "custom Price" which have been generated on the Product-Site to the product Price on the cart.

With the actual code it is only the value (price) of the hidden field which is delivered to the cart - without the product price.

Code with checkout_cart_product_add_after:

public function change_price(Varient_Event_Observer $observer) {



    $item = $observer->getQuoteItem();

    if ($item->getParentItem()) {
        $item = $item->getParentItem();
    }

    $newpricetest = Mage::app()->getRequest()->getPost('priceInput');

    $new_price = $item->getOriginalPrice() + $newpricetest;

    $item->setCustomPrice($new_price);
    $item->setOriginalCustomPrice($new_price);
    $item->getProduct()->setIsSuperMode(true);

}

What's wrong?

  • Check with some logging in method to see upto which point it is working. This should be as simple as Mage::log('123'); in various places and different values. Make sure you have logging enabled from admin. – Prateek Mar 11 '16 at 13:52
  • that will work seems ur module is not working i had done same before also – mcoder Mar 11 '16 at 17:39
3

Using sales_quote_add_item event observer is working for me.

config.xml

<frontend>
    <events>
        <sales_quote_add_item>
            <observers>
                <mymodule_observer>
                    <type>singleton</type>
                    <class>MyCompany_MyModule_Model_Observer</class>
                    <method>updateCartPrice</method>
                </mymodule_observer>
            </observers>
        </sales_quote_add_item>
    </events>
</frontend> 

Observer.php

class MyCompany_MyModule_Model_Observer
{
    public function updateCartPrice(Varien_Event_Observer $observer)
    {
        $event = $observer->getEvent();        
        $quoteItem = $event->getQuoteItem();
        //$product = $item->getProduct();        

        $customPrice = YOUR_CUSTOM_PRICE;
        $quoteItem->setOriginalCustomPrice($customPrice);
        $quoteItem->save(); 
    }    
}
1

Better to use catalog_product_get_final_price observer and set the custom price before adding to the cart would be an easy win. Using add after requires manual collect totals and save.

Your Answer

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

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