Jump to content

Custom xml currency rates 1.7.2.4


zelddaniel

Recommended Posts

Hello, I was wondering through the prestashop forum and all that i find is solution for Prestashop 1.6 or older.. here, here and here

Probably the answer is inbetween but I dont speak "programmer" so good.

 

Could anyone please share a method as how we could add our own bank currency rates, such as http://www.bnr.ro/nbrfxrates.xml ?

 

Many thanks in advance, from me and all romanians :) 

Edited by zelddaniel (see edit history)
Link to comment
Share on other sites

I tried 

 public static function refreshCurrencies()
    {
        // Parse
        if (!$feed = Tools::simplexml_load_file('http://www.bnr.ro/nbrfxrates.xml')) {
            return Context::getContext()->getTranslator()->trans('Cannot parse feed.', array(), 'Admin.Notifications.Error');
        }

        // Default feed currency (EUR)
        $isoCodeSource = strval($feed->source['EUR']);

        if (!$defaultCurrency = Currency::getDefaultCurrency()) {
            return Context::getContext()->getTranslator()->trans('No default currency', array(), 'Admin.Notifications.Error');
        }

        $currencies = Currency::getCurrencies(true, false, true);
        foreach ($currencies as $currency) {
            /** @var Currency $currency */
            if ($currency->id != $defaultCurrency->id) {
                $currency->refreshCurrency($feed, $isoCodeSource, $defaultCurrency);
            }
        }

        return '';
    }

 

Edited by zelddaniel (see edit history)
Link to comment
Share on other sites

  • 2 weeks later...
  • 2 weeks later...
  • 6 months later...

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
×
×
  • Create New...