cancel
Showing results for 
Search instead for 
Did you mean: 

How can update Grand Total on observer in Magento?

How can update Grand Total on observer in Magento?

 

 

I have an observer for the event

sales_quote_collect_totals_after

and I want to change the Grand Total for not logged in. I tried with:

$value = 100;

$quote = $observer->getQuote();

$quote->setGrandTotal($value);

$quote->setTotalsCollectedFlag(false)->collectTotals();

$quote->save();

or 

$value = 100;

$quote = $observer->getQuote();

$quote->setGrandTotal($value);

$quote->collectTotals();

$quote->save();

But it doesn't work. Any ideas?

Thanks.

Tags (2)
2 REPLIES

Re: How can update Grand Total on observer in Magento?

To update grand total, It is better to override sales quote total.

Write the below code in your config.xml file.

 

<sales>
<quote>
<totals>
<extension_class>
<class>Vendor_Extension_Model_Sales_Quote_Address_Total_Settotal</class>
<after>shipping</after>
</extension_class>
</totals>
</quote>
</sales>

and write below code in 'Vendor_Extension_Model_Sales_Quote_Address_Total_Settotal' file at your desired location.

 

 

<?php
class Vendor_Extension_Model_Sales_Quote_Address_Total_Settotal extends Mage_Sales_Model_Quote_Address_Total_Abstract
{
public function collect(Mage_Sales_Model_Quote_Address $address)
{
$items = $address->getAllItems();
if (!count($items)) {
return $this;
}
$quoteId = Mage::getSingleton('checkout/session')->getQuoteId();
$quote = Mage::getModel('sales/quote')->load($quoteId);
if($quote->getBaseGrandTotal() > 0)
{
$address->setGrandTotal(10);
$address->setBaseGrandTotal(10);
}
return $this;
}
}

 

 

Found something useful, please give "Kudos" or "Accept as Solution" for Token of Appreciation.
Free Magento Extensions : https://magecomp.com/free-magento-extensions.html

Re: How can update Grand Total on observer in Magento?

Thanks for reply @theMageComp

But, we want to change the Grand Total for not logged in.

We need to set without override sales quote total.

If you have any idea please reply.