Custom totals collector: Reorder totals in totals overview in checkout

Custom totals collector: Reorder totals in totals overview in checkout

September 12, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Custom totals collector: Reorder totals in totals overview in checkout
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Reorder Totals in Checkout Overview</title>
</head>

<body style="font-family: Arial, sans-serif;">

<h1>Custom Total Collector: Reordering Totals in the Checkout Overview</h1>

<p>The custom total collector you've implemented is a good starting point for applying discounts based on customer qualifications. However, you're facing challenges with reordering the totals in the checkout overview and understanding how the "before" and "after" config elements work.</p>

<strong>Understanding the Total Collector Configuration</strong>

<p>The <code>sales/quote/totals</code> configuration section defines the order of total collectors during quote calculation. Each collector is defined by its own XML node, which includes the following attributes:</p>

<ul>
    <li><strong>class</strong>: The PHP class responsible for calculating the total.</li>
    <li><strong>before/after</strong>: These elements define the order of the collectors relative to other totals. They take values like "subtotal", "tax", "shipping", etc.</li>
</ul>

<strong>Changing the Total Order</strong>

<p>The issue with reordering your custom total is that Magento processes totals in a specific sequence defined by the <code>after</code> attribute. Currently, you're positioning your discount after shipping:</p>

```xml
<my_discount>
    <class>My_Module_Model_DiscountCollector</class>
    <after>shipping</after>
</my_discount>

To place your discount before shipping and after the subtotal, update the configuration as follows:

<my_discount>
    <class>My_Module_Model_DiscountCollector</class>
    <before>shipping</before>
</my_discount>

This change orders the totals in the checkout overview to "Subtotal, My Discount (3%), Shipping, Grand Total". However, you're right that changing the position of your total doesn't affect its inclusion in the grand total calculation.

The Impact on Grand Total Calculation

The relationship between a total collector and the grand total is complex. Changing the "before" or "after" attributes doesn't directly determine whether a total affects the grand total—it simply changes the sequence of total calculations.

The inclusion of your discount in the grand total calculation depends on how you’ve implemented the collect() method of your collector and its interaction with other totals, especially tax and shipping.

In your current implementation, you're only subtracting the discount amount from the subtotal. If you want this discount to also affect the final grand total, you need to ensure that it is calculated after all other totals have been applied.

To achieve this, update your collect() method as follows:

public function collect(Mage_Sales_Model_Quote_Address $address)
{
    // Existing logic...
    if ($this->userIsQualified()) {
        parent::collect($address);

        // Calculate the base and non-tax-adjusted discount amounts here...

        // Add the discount to the grand total
        $address->setGrandTotal($address->getGrandTotal() - $baseDiscountAmount);
    }
}

This modification ensures that your discount is applied after all other totals, including tax and shipping, thereby affecting the final grand total.

Conclusion

Reordering totals in the checkout overview requires careful configuration of the before and after attributes in the sales/quote/totals section.

However, the inclusion of your custom total in the grand total calculation depends on the specific implementation details of your collector class, especially how it interacts with other totals during the collection process.

By updating both the configuration and the collector logic, you can achieve a more comprehensive solution that meets all your requirements for displaying and calculating discounts in the checkout overview.

If you’re still facing issues or need further assistance, feel free to explore our Magento development blog at Laravel Company for additional resources on customizing Magento totals collectors.

```
Checkout Extensions Configuration Orders

Our network