How to set Grandtotal / BaseGrandTotal with Observer?

How to set Grandtotal / BaseGrandTotal with Observer?

August 16, 2026 · Illustrated author avatarBy Stefan Bogdanescu
How to set Grandtotal / BaseGrandTotal with Observer?

Setting Grand Total and Base Grand Total with Observer: A Comprehensive Guide

Introduction In Magento e-commerce platforms, setting the grand total and base grand total is a crucial aspect of the checkout process. This involves more than just calculation; it requires proper configuration and implementation through observers to affect changes in real-time. In this post, we will guide you through the process, focusing on Magento 1.6.2.

Understanding the Problem You’ve correctly configured your config.xml file with the observer setup:

<sales_quote_collect_totals_before>
    <observers>
        <discount>
            <class>discount/observer</class>
            <method>discountMethod</method>
        </discount>
    </observers>
</sales_quote_collect_totals_before>

And you’ve implemented the observer method in Observer.php:

public function discountMethod($observer)
{
   $quote = $observer->getEvent()->getQuote();
   $quote->setGrandTotal(1);
   $quote->setBaseGrandTotal(1);
   $quote->save();
}

However, you’re facing an issue where the actual displayed grand total on the checkout page (checkout/onepage/index) remains unaffected by your observer changes. The quote data shows the correct values:

[grand_total] => 1
[base_grand_total] => 1

But the visual display still reflects the original, unmodified prices.

Diagnosing the Issue The core problem lies in how Magento handles and displays the grand total during the checkout process. The checkout/onepage/index action triggers multiple events that calculate totals independently of your observer setup.

Step 1: Identifying the Core Problem Magento calculates the grand total in multiple places, including the Mage_Sales_Model_Quote class’s _getGrandTotal() and Mage_Checkout_Block_Onepage_Totals block. These areas are not affected by your observer method.

Step 2: Why Your Observer Isn’t Working Your current observer is triggered before the totals are collected (sales_quote_collect_totals_before), but it doesn’t actually update the displayed values on the page. The setGrandTotal() and setBaseGrandTotal() methods merely update the quote data, which isn’t reflected in the rendering of the checkout page.

The Solution: Correct Observer Setup

To successfully set the grand total and base grand total during checkout, you need to modify your observer setup and method:

  1. Change the observation event from sales_quote_collect_totals_before to checkout_onepage_controller_success_action. This ensures that your observer is triggered after all other total calculations are performed.
<checkout_onepage_controller_success_action>
    <observers>
        <discount>
            <class>discount/observer</class>
            <method>discountMethod</method>
        </discount>
    </observers>
</checkout_onepage_controller_success_action>
  1. Modify your Observer.php method:
public function discountMethod($observer)
{
   $quote = Mage::getSingleton('checkout/session')->getQuote();
   $quote->setGrandTotal(1);
   $quote->setBaseGrandTotal(1);
   $quote->collectTotals()->save();
}

Key Changes:

  • Use Mage::getSingleton('checkout/session')->getQuote() to retrieve the quote object from the session.
  • Add $quote->collectTotals() before calling $quote->save(). This ensures that all totals are recalculated after your modifications.

Conclusion

Setting the grand total and base grand total correctly requires a deep understanding of Magento’s event-driven architecture, particularly during the checkout process. By adjusting your observer configuration to use the checkout_onepage_controller_success_action event and modifying your method to ensure total recalculation before saving, you can effectively set and display the desired values on the checkout page.

Remember, Magento 1.x systems are now considered legacy by many in the e-commerce community. For new projects or significant updates, we recommend considering a migration to Magento 2 LINK, which offers improved performance and features.

This solution should resolve your issue with setting grand total and base grand total in your current Magento 1.6.2 setup while checking out.

Magento 1 Checkout Extensions Configuration

Our network