cancel
Showing results for 
Search instead for 
Did you mean: 

Change currently selected payment method using obbserver

Change currently selected payment method using obbserver

Hello friends

 

how I can change my current selected payment method using obbserver after clicking place order if grand total is zero

 

On my checkout page user first select payment method & then order review there is option for add coupon code. On place order if my grand total is zero then what i want is to change payment method to "free" from "paypal"

 

How i can do this please help. My code sample is attached here

 

/****** config.xml ************/
<frontend>
        <events>
            <sales_order_place_before>
                <observers>
                    <change_payment_method_on_zero>
                        <type>singleton</type>
                        <class>Obbserv_Discountcouponcheckout_Model_Observer</class>
                        <method>changePaymentMethodOnZero</method>
                    </change_payment_method_on_zero>
                </observers>
            </sales_order_place_before>
        </events>
    </frontend>
/********** Obbserver.php *************/

class Obbserv_Discountcouponcheckout_Model_Observer
{
    public function changePaymentMethodOnZero(Varien_Event_Observer $observer)
    {
        $order = $observer->getEvent()->getOrder();
        if($order->getGrandTotal() == 0)
        {
            $payment = $order->getPayment();
            $payment->setMethod('free');
            $payment->save();
        }
    }
}

 

 

But this code did not work as desire. Also record is even not updating in "sales_flat_quote_payment" table

 

.