Magento – Change Price of configurable quote item with observer

configurable-productevent-observermagento-1.8quotequoteitem

I want to change the price of a configurable product I put in my quote. I use the observer sales_quote_add_item but it won't work for configurable products.
I expect the observer method to run twice (for the simple and configurable record that's put in the database) but it's only called once (for the simple product). The record for configurable still has the old prices.

Can anyone tell me how I can change the price for the complete quote-item in such a way that it will also be seen on cart overview, invoices and emails?

Best Answer

I figured it out myself. You need to observe the event checkout_cart_product_add_after. In the observer you need the following:

public function change_price(Varient_Event_Observer $observer) {
    // get the quote
    $item = $observer->getQuoteItem();

    // checks for parent item
    if ($item->getParentItem()) {
        $item = $item->getParentItem();
    }

    // your price logic here
    $new_price = 999;

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