Jump to content

Change order currency to a specific currency


wss
 Share

Recommended Posts

Hi all!

Following the post here:
 



I changed my tools.php display price function from this:

    public static function displayPrice($price, $currency = null, $no_utf8 = false, Context $context = null)
    {
        if (!is_numeric($price)) {
            return $price;
        }
        if (!$context) {
            $context = Context::getContext();
        }
        if ($currency === null) {
            $currency = $context->currency;
        } elseif (is_int($currency)) {
            $currency = Currency::getCurrencyInstance((int) $currency);
        }

        $cldr = self::getCldr($context);

        return $cldr->getPrice($price, is_array($currency) ? $currency['iso_code'] : $currency->iso_code);
    }


To this:
 

    public static function displayPrice($price, $currency = null, $no_utf8 = false, Context $context = null)
    {
        if (!is_numeric($price)) {
            return $price;
        }
        if (!$context) {
            $context = Context::getContext();
        }
        if ($currency === null) {
        if ($context->controller->php_self == 'order') {
            $currency = Currency::getCurrencyInstance(2);
        } else { $currency = $context->currency;}

        /* "else in the tutorial above" was $currency = Currency::getCurrencyInstance((int)2) ; this code shows always the currency (int)2 when we are not in orders, also when the currency chosen by the visitor is (int)1 or another currency, so I changed the code */


        } elseif (is_int($currency)) {
            if ($context->controller->php_self == 'order') {
            if ( $currency == '3' ) {
            $price = Tools::convertPrice($price, 3, 2, false);
            }
            else $currency = Currency::getCurrencyInstance(2);
            } else
           {            $currency = Currency::getCurrencyInstance((int) $currency);

        /* "else in the tutorial above" was $currency = Currency::getCurrencyInstance((int)2) ; but the code shows always the currency (int)2 when we are not in orders, also when the currency chosen by the visitor is (int)1 or another currency, so I changed the code */
        }
        }

        $cldr = self::getCldr($context);

        return $cldr->getPrice($price, is_array($currency) ? $currency['iso_code'] : $currency->iso_code);
    }



The function seems to work fine, and the currency sign changes in the order phase, but the price is not converted / updated with the right currency, and moreover I know convertPrice is deprecated, so I'm looking for help.

What I'm trying to do is to process the orders always in a specific currency (EUR, currency ID=2), and change the order confirmation page / checkout page to EUR, regardless of the store currency that was chosen by the customer (GBP, currency ID=3).

In the store I have only 2 currencies (ID# 2 and 3) and I'm on PS 1.7.5.0.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More