Forum PrestaShop

Il Forum di PrestaShop è lo spazio in cui puoi condividere con la comunità di PrestaShop consigli pratici sull'e-commerce e trovare la risposta a tutte le domande tecniche e funzionali.

Forum PrestaShop

Jump to content

 

[SOLVED]Currency update

32 replies to this topic
#1
bebba

    PrestaShop Apprentice

  • Members
  • PipPip
  • 120 posts
How does the currency update work. Iget an error?

#2
SpyrosT

    PrestaShop Apprentice

  • Members
  • PipPip
  • 305 posts
I have 3 currencies in my shop and the update works fine.

#3
rocky

    PrestaShop Superstar

  • US Moderators
  • 9988 posts
Your server configuration may be blocking PrestaShop's call to the currency XML feed. You'll need to contact your host and ask them to unblock it.
Check out Nethercott Constructions for PrestaShop guides and modules. Like us on Facebook for news updates.

#4
bebba

    PrestaShop Apprentice

  • Members
  • PipPip
  • 120 posts
OK, is ther an currency XML file then, wher?

#5
rocky

    PrestaShop Superstar

  • US Moderators
  • 9988 posts
It is http://www.prestasho...currencies.xml. If PrestaShop can't access that file, then it can't update the currency rates.
Check out Nethercott Constructions for PrestaShop guides and modules. Like us on Facebook for news updates.

#6
bebba

    PrestaShop Apprentice

  • Members
  • PipPip
  • 120 posts
So that file is on Pretashop.com server?, wher/ in witsh file in my shop is the link to the file supose to be?

#7
rocky

    PrestaShop Superstar

  • US Moderators
  • 9988 posts
The file isn't in your shop. It is read directly from the PrestaShop server. That's why it isn't working for you. Your server configuration isn't letting PrestaShop read it off the server.
Check out Nethercott Constructions for PrestaShop guides and modules. Like us on Facebook for news updates.

#8
bebba

    PrestaShop Apprentice

  • Members
  • PipPip
  • 120 posts
OK, i'v asked my server company to look at this.

I found this code in \Classes\currency.php

static public function refreshCurrencies()
{
if (!$feed = @simplexml_load_file('http://www.prestashop.com/xml/currencies.xml'))
return Tools::displayError('Cannot parse feed!');
if (!$defaultCurrency = intval(Configuration::get('PS_CURRENCY_DEFAULT')))
return Tools::displayError('No default currency!');
$isoCodeSource = strval($feed->source['iso_code']);
$currencies = self::getCurrencies(true);
$defaultCurrency = self::refreshCurrenciesGetDefault($feed->list, $isoCodeSource, $defaultCurrency);
foreach ($currencies as $currency)
if ($currency->iso_code != $defaultCurrency->iso_code)
$currency->refreshCurrency($feed->list, $isoCodeSource, $defaultCurrency);
}
}

?>

Does ths look right, can you compare whit your file? is this file supose to be 777?

#9
rocky

    PrestaShop Superstar

  • US Moderators
  • 9988 posts
That's the same as my file. The problem is that your server is returning false when @simplexml_load_file('http://www.prestashop.com/xml/currencies.xml') in executed, whereas it is returning the feed on my server.
Check out Nethercott Constructions for PrestaShop guides and modules. Like us on Facebook for news updates.

#10
bebba

    PrestaShop Apprentice

  • Members
  • PipPip
  • 120 posts
OK so thet file des not have to be 777

#11
rocky

    PrestaShop Superstar

  • US Moderators
  • 9988 posts
No, classes/Currency.php does not need to be chmod 777, and you can't change the permissions on the currencies.xml file since it is on PrestaShop's server.
Check out Nethercott Constructions for PrestaShop guides and modules. Like us on Facebook for news updates.

#12
bebba

    PrestaShop Apprentice

  • Members
  • PipPip
  • 120 posts
I get a question from my server admin, (What is required for the service to work? In what way is the XML feeds retrieved through "PrestaShop"?

What do i answer. Can i show them the classes/currency.php file?

#13
rocky

    PrestaShop Superstar

  • US Moderators
  • 9988 posts
Just ask them whether your server is configured to allow @simplexml_load_file('http://www.prestashop.com/xml/currencies.xml') to work.
Check out Nethercott Constructions for PrestaShop guides and modules. Like us on Facebook for news updates.

#14
bebba

    PrestaShop Apprentice

  • Members
  • PipPip
  • 120 posts
The server admin replayed this:

Seems as if this is fopen, which is not permitted on our servers. Tip is that you us a curl script to first get home this locally and then see if it works to read it.

#15
rocky

    PrestaShop Superstar

  • US Moderators
  • 9988 posts
It looks like you'll need to change to a server that uses fopen or rewrite PrestaShop's code to use cURL. I did a Google search and found this site which has cURL code. You could try using code similar to it. Unfortunately, I'm not familiar with cURL, so I can't help any more.
Check out Nethercott Constructions for PrestaShop guides and modules. Like us on Facebook for news updates.

#16
bebba

    PrestaShop Apprentice

  • Members
  • PipPip
  • 120 posts
OK i got a file from the server admin, this is the kode: see img.



i wright http://www.prestasho.../currencies.xml - insted of http://www.loopia.se/ - But wher do i put in the serchway/link to this file?

The filename is: file_get_url_contents.php

Do you think this will work?

Attached Files



#17
bebba

    PrestaShop Apprentice

  • Members
  • PipPip
  • 120 posts
How do i rewrite PrestaShop’s code to use cURL?

#18
rocky

    PrestaShop Superstar

  • US Moderators
  • 9988 posts
Yes, that should work. Use that code to get the currencies.xml file as a string, then use the following code to read the string into XML:


$feed = @simplexml_load_string($res);

Check out Nethercott Constructions for PrestaShop guides and modules. Like us on Facebook for news updates.

#19
bebba

    PrestaShop Apprentice

  • Members
  • PipPip
  • 120 posts
OK, so do iput in the code i got from server admin in to classes/Currency.php insted of http://www.prestasho...currencies.xml. and den insert the code to read the string into XML after that code?

#20
rocky

    PrestaShop Superstar

  • US Moderators
  • 9988 posts
Replace the refreshCurrencies() function on lines 217-229 of classes/Currency.php (in PrestaShop v1.3):


static public function refreshCurrencies()
{
if (!$feed = @simplexml_load_file('http://www.prestashop.com/xml/currencies.xml'))
return Tools::displayError('Cannot parse feed!');
if (!$defaultCurrency = intval(Configuration::get('PS_CURRENCY_DEFAULT')))
return Tools::displayError('No default currency!');
$isoCodeSource = strval($feed->source['iso_code']);
$currencies = self::getCurrencies(true);
$defaultCurrency = self::refreshCurrenciesGetDefault($feed->list, $isoCodeSource, $defaultCurrency);
foreach ($currencies as $currency)
if ($currency->iso_code != $defaultCurrency->iso_code)
$currency->refreshCurrency($feed->list, $isoCodeSource, $defaultCurrency);
}


with the following two functions:


static public function file_get_url_contents($url) {
if (preg_match('/^([a-z]+):\/\/([a-z0-9-.]+)(\/.*$)/i', $url, $matches)) {
$protocol = strtolower($matches[1]);
$host = $matches[2];
$path = $matches[3];
} else {
// Bad url-format
return FALSE;
}

if ($protocol == "http") {
$socket = fsockopen($host, 80);
} else {
// Bad protocol
return FALSE;
}

if (!socket) {
// Error creating socket
return FALSE;
}

$request = "GET $path HTTP/1.0\r\nHost: $host\r\n\r\n";
$len_written = fwrite($socket, $request);

if ($len_written === FALSE || $len_written != strlen($request)) {
// Error sending request
return FALSE;
}

$response = "";
while (!feof($socket) && ($buf = fread($socket, 4096)) !== FALSE) {
$response .= $buf;
}

if ($buf === FALSE) {
// Error reading response
return FALSE;
}

$end_of_header = strpos($response, "\r\n\r\n");
return substr($response, $end_of_header + 4);
}

static public function refreshCurrencies()
{
$url = "http://www.prestashop.com/xml/currencies.xml";
$res = self::file_get_url_contents($url);
if ($res === FALSE)
return Tools::displayError("Error fetching $url");
else
{
if (!$feed = @simplexml_load_string($res))
return Tools::displayError('Cannot parse feed!');
if (!$defaultCurrency = intval(Configuration::get('PS_CURRENCY_DEFAULT')))
return Tools::displayError('No default currency!');
$isoCodeSource = strval($feed->source['iso_code']);
$currencies = self::getCurrencies(true);
$defaultCurrency = self::refreshCurrenciesGetDefault($feed->list, $isoCodeSource, $defaultCurrency);
foreach ($currencies as $currency)
if ($currency->iso_code != $defaultCurrency->iso_code)
$currency->refreshCurrency($feed->list, $isoCodeSource, $defaultCurrency);
}
}

Check out Nethercott Constructions for PrestaShop guides and modules. Like us on Facebook for news updates.