1

I have made a module that sets custom prices of quote items upon a cart update. For that I use these events:

checkout_cart_product_add_after
sales_quote_remove_item
checkout_cart_update_items_after

It works fine but the problem is that the custom prices are not recalculated if user proceeds to checkout or sends the order.

I would like them to be recalculated there as well because they are derived from data that possibly might have been changed from the last cart update (user group, product base price, etc.). Magento recalculates its prices this way if a custom price is not set so I would like to achieve the same behaviour.

Are there the appropriate events to hook in to invoke the recalculation in my module?

EDIT: In fact, it seems that Magento recalculates prices even after normal page reloads in cart. I guess I don't really need this even though it is more correct.

1 Answer 1

6

I use the event salesQuoteCollectTotalsBefore set the price on the product and then it is transfered to the quoteItem:

public function salesQuoteCollectTotalsBefore(Varien_Event_Observer $observer)
{
    /* @var $quote Mage_Sales_Model_Quote */
    $quote = $observer->getQuote();
    foreach ($quote->getAllItems() as $quoteItem) {
        if (true) {
            /* @var $quoteItem Mage_Sales_Model_Quote_Item */
            $product = $quoteItem->getProduct();
            $price = $helper->getPriceWithoutTax($quoteItem);
            $product->setPrice($price);
        }
    }
}
1
  • Ye, sales_quote_collect_totals_before is nice. I guess it covers all I need (any cart update, proceeding to checkout, submitting order). For setting the prices I personally use setCustomPrice and setOriginalCustomPrice. I didn't know about the method you are using. Thanks for the answer!
    – clime
    May 16, 2013 at 23:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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