I am trying to set particular payment method in Magento session programatically in methods.phtml
. I know how to retrieve current selected payment method from Magento session using getSingleton
. But I am not able to find out how to override the existing selected payment method in the session.
I want to directly update the session variable for payment method. Is there anything like Mage::getSingleton('checkout/session')->setMethod('$method')
. I have tried every other solution. If there is any function like this then please help me.
how to set particular payment method in magento programatically in methods.phtml using getsingleton?
-
I just want to set payment method in magento session programatically ..– Dinesh BelakareCommented Nov 12, 2013 at 13:50
Add a comment
|
2 Answers
I'm not sure I understand your question, but here goes. You can try this:
$quote = Mage::getSingleton('checkout/session')->getQuote();
$methodCode = 'payment_code_here';
if ($quote->isVirtual()) {
$quote->getBillingAddress()->setPaymentMethod($methodCode);
} else {
$quote->getShippingAddress()->setPaymentMethod($methodCode);
}
$quote->save();
Looking at your code I noticed you are putting your variable in quotes. Not sure if you noticed that or not but it should look like.
Mage::getSingleton('checkout/session')->setMethod($method);
not
Mage::getSingleton('checkout/session')->setMethod('$method')