Josua M C
Josua M C

Reputation: 3158

How to set Grandtotal / BaseGrandTotal with Observer?

Config.xml

        <sales_quote_collect_totals_before>
            <observers>
                <discount>
                    <class>discount/observer</class>
                    <method>discountMethod</method>
                </discount>
            </observers>
        </sales_quote_collect_totals_before>

Observer.php

public function discountMethod($observer)
{
   $quote = $observer->getEvent()->getQuote();
   $quote->setGrandTotal(1);
   $quote->setBaseGrandTotal(1);
   $quote->save();
}

I've already created the config.xml and Observer.php and that code doesn't work at all. $quote->getData() shows:

[grand_total] => 1
[base_grand_total] => 1

But the GrandTotal on page still show the true price GrandTotal

I'm using Default Magento 1.6.2 and on checkout/onepage/index the function is triggered every I clicked continue but I don't know how to set the grandTotal / BaseGrandTotal on quote.

Upvotes: 2

Views: 5185

Answers (1)

Justus Krapp
Justus Krapp

Reputation: 1116

you are listening to sales_quote_collect_totals_before so the totals including the grandTotal are collected after this event and the total collector will reset grandTotal to 0 when it runs.

if you are using sales_quote_collect_totals_after instead the total should be correct but the tax calculation will be messed up, because it will be based on the old totals.

the only clean way i can think of is creating your own total collector with <before>tax</before>

here is a link on how to create a new total collector: http://magento.ikantam.com/qa/how-add-discount-total-magento

hope that helps

Upvotes: 4

Related Questions