Skip to content
Advertisement

Magento, getSubtotal and getGrandTotal always return zero

I have a weird problem. I have developed a module which adds a line to totals according to some value in database. But in my module model (which is inherited from Mage_Sales_Model_Quote_Address_Total_Abstract) when I call

$address->getSubtotal()

or

$address->getGrandTotal()

or any other totals method, I get zero (0) returned. But in phpmyadmin, I see that those values are not zero. Any other column except these totals columns returns their correct value (i.e, getAddressId() return the ID, getAddressType returns “shipping” etc.)

What may be the problem, any idea? Thanks ———- EDIT ———– OK, After @Alan Storm’s comment, I see that I should be more clear. I’m trying to develop an instalment module. I will set instalment fees (changing according to months count) in the admin, and I will add this fee to cart total at the checkout.

This is my collect method,

public function collect(Mage_Sales_Model_Quote_Address $address)
{

$address->setInstalmentCount(2); //instalment count is hardcoded as 2 for debugging

$paymentMethod = Mage::app()->getFrontController()->getRequest()->getParam('payment');
$paymentMethod = Mage::app()->getStore()->isAdmin() && isset($paymentMethod['method']) ? $paymentMethod['method'] : null;
if ($paymentMethod != 'oos' && (!count($address->getQuote()->getPaymentsCollection()) || !$address->getQuote()->getPayment()->hasMethodInstance())){            
    return $this;
}

$paymentMethod = $address->getQuote()->getPayment()->getMethodInstance();

if ($paymentMethod->getCode() != 'oos') {            
    return $this;
}

$items = $address->getAllItems();
if (!count($items)) {
    return $this;
}

$baseTotal = $address->getBaseGrandTotal();   // THIS ALWAYS RETURNS ZERO

// adress is the reference for grand total
$quote = $address->getQuote();
$store = $quote->getStore();

$fee_perc = $oosconfig['inst' . round($address->getInstalmentCount())]; // get the setting from admin
$ins_fee = $store->convertPrice($baseTotal*$fee_perc/100.0, false); // calculate the fee    

$baseTotal += $ins_fee; // add to totals

$address->setInstalmentFee($ins_fee);

// update totals
$address->setBaseGrandTotal($baseTotal);
$address->setGrandTotal($store->convertPrice($baseTotal, false));    

return $this;   

}

—— EDIT2 ——

OK guys, I have figured it out! The problem was with my config.xml I should have added

<after>grand_total</after>

Since it is absent, it was first collecting my module’s total while subtotal and grand_total were not calculated yet. Because of this, they were coming as zeros.

Thank you though!

Advertisement

Answer

Adding the OPs “Self Help Desk” answer. If you like it, be sure to up vote the original question.

OK guys, I have figured it out! The problem was with my config.xml I should have added

<after>grand_total</after>

Since it is absent, it was first collecting my module’s total while subtotal and grand_total were not calculated yet. Because of this, they were coming as zeros.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement