How to Change Currency for Quote in Onepage Checkout – Magento 1.9

currencymagento-1.9onepage-checkout

I want to change the currency to USD for a quote depending on shipping method in Onepage checkout. The new currency should be reflected in the order review before going to the payment provider. A bonus would be if both currencies can be shown in the review, but only USD is also fine.

Nothing I do seem to have any effect, even though I recompile and empty the cache between . This is my current attempt:

app/code/local/Mage/Checkout/controllers/OnepageController.php

/**
 * Save payment ajax action
 *
 * Sets either redirect or a JSON response
 */
public function savePaymentAction()
{
    if ($this->_expireAjax()) {
        return;
    }
    try {
        if (!$this->getRequest()->isPost()) {
            $this->_ajaxRedirectResponse();
            return;
        }

        $data = $this->getRequest()->getPost('payment', array());
        $result = $this->getOnepage()->savePayment($data);
        if ($data['method'] == 'ourpaymentmethodofchoice') {
            Mage::app()->getStore()->setCurrentCurrencyCode('USD');
        }
    // etc

I have also tried this:

            $currency = Mage::getModel('directory/currency')->load('USD')
            $quote = $this->getOnepage()->getQuote();
            $quote->setForcedCurrency($currency);
            $quote->save();
            $this->getOnepage()->saveOrder();

We are running Magento 1.9.

What is the best way to change the currency programatically?

Best Answer

donot use

$this->getOnepage()->saveOrder(); fire order place.

Add below code after Mage::app()->getStore()->setCurrentCurrencyCode('USD');

$this->getOnepage()->getQuote()->collectTotals()->save(); for calculate quote price

Related Topic