Magento: Custom totals counted twice?

Magento: Custom totals counted twice?

July 25, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento: Custom totals counted twice?

Resolving Duplicate Total Calculation Issues in Magento

Introduction

Are you facing duplicate total calculations in your Magento store? It’s a common issue that many developers struggle to resolve. In this post, we’ll dive deep into understanding why your custom totals might be calculated twice and provide practical solutions to fix this problem.

The Issue: Custom Totals Calculated Twice

You’ve created a custom Total class for adding a special discount, but somehow the total is being calculated twice on certain pages like the cart page and checkout pages. This results in a double amount of discount and an incorrect grand total. The strange part? The calculation is fine when completing the order.

Why Does This Happen?

The issue likely arises from how Magento processes totals during the shopping cart and checkout process. Totals are recalculated at various stages, such as when adding items to the cart or applying discounts. However, it seems that your custom total class might be getting called more than once in these scenarios.

Analyzing Your Code

Let’s examine the key parts of your code:

  1. Configuration XML: The configuration is correctly set up with the total being defined before subtotal, which is a good practice.
<sales>
  <quote>
    <totals>
      <mydiscount>
        <class>ucon_mydiscount/total_mydiscount</class>
        <before>subtotal</before>
      </mydiscount>
    </totals>
  </quote>
</sales>
  1. Collector Method: The collector is correctly setting the amount and base amount for the discount.
public function collect(Mage_Sales_Model_Quote_Address $address)
{
    // Existing code...

    $this->_setAmount($discount);
    $this->_setBaseAmount($discount);

    return $this;
}
  1. Fetcher Method: The fetcher is correctly adding the total to the address.
public function fetch(Mage_Sales_Model_Quote_Address $address)
{
    // Existing code...

    if ($amount != 0) {
        $title = Mage::helper('ucon_mydiscount')->__('My discount');
        $address->addTotal(array(
            'code' => $this->getCode(),
            'title' => $title,
            'value' => $amount
        ));
    }

    return $this;
}

Potential Causes and Solutions

There could be several reasons for this issue:

  1. Event Observers: Check if you have any event observers that are calling the total collector again under certain conditions.

  2. Core Overrides or Plugins: If you’ve overridden core Magento classes, especially those related to totals calculation (like Mage_Sales_Model_Quote_Total_Abstract), ensure there are no conflicting changes.

  3. Third-Party Extensions: Some third-party extensions might interfere with total calculations if they have incompatible logic.

To troubleshoot:

  • Enable logging in your custom Total class to see how many times the collector is being called.
  • Use a debugging tool like Xdebug or Mage::log() to trace what’s happening during the cart and checkout process.
  • Check for any conflicting changes in the core codebase or other extensions.

Conclusion: Finding the Root Cause

Resolving this issue requires a methodical approach:

  1. Isolate the Problem: Determine if it’s an issue with your custom Total class, Magento’s core logic, or third-party extensions.

  2. Enable Logging and Debugging: Use logging and debugging tools to track where the collector is being called multiple times.

  3. Review Code Changes: Thoroughly review any code changes, overrides, or plugins that might be causing the issue.

  4. Test and Refine: Make necessary adjustments based on your findings and retest in a staging environment before deploying changes to production.

Remember, Magento’s total calculation process is complex due to its object-oriented architecture and multiple stages of processing during checkout. Patience and systematic troubleshooting are key to resolving this issue effectively.

For more detailed guides on customizing totals in Magento, I recommend checking out our comprehensive guide at https://laravelcompany.com/magento-custom-totals-guide.

Checkout Configuration Orders Pricing

Our network