Magento – Add Custom Total to Cart’s GrandTotal in Magento

checkoutmoduletotals

I'm trying to add an oversized fee for large products. Most of what that entails is a little more complicated than I want to explain here. Basically, I've built a custom function to check if the product is oversized and assign the appropriate shipping cost. However, I can't figure out how to get that value added into the grand total at check out.

Best Answer

Magento automatically combines the subtotal and grandtotal of the addresses for you, see Mage_Sales_Model_Quote::collectTotals

        $this->setSubtotal((float) $this->getSubtotal()+$address->getSubtotal());
        $this->setBaseSubtotal((float) $this->getBaseSubtotal()+$address->getBaseSubtotal());

        $this->setGrandTotal((float) $this->getGrandTotal()+$address->getGrandTotal());
        $this->setBaseGrandTotal((float) $this->getBaseGrandTotal()+$address->getBaseGrandTotal());

Adding your extra charge to the address subtotal and grandtotal will ensure it is reflected in the overall grand total.

For more in depth reading on the checkout process I can thoroughly recommend this post by Chris @ Classy Llama.