Posted By

bogdandev on 07/19/12


Tagged

currency magento webservicex


Versions (?)

magento webservicex with google convertor URL


 / Published in: PHP
 

replace /app/code/core/Mage/Directory/Model/Currency/Import/Webservicex.php

  1. <?php
  2. /**
  3.  * Currency rate import model (From www.webservicex.net)
  4.  *
  5.  * @category Mage
  6.  * @package Mage_Directory
  7.  * @author Magento Core Team <[email protected]>
  8.  */
  9. class Mage_Directory_Model_Currency_Import_Webservicex extends Mage_Directory_Model_Currency_Import_Abstract
  10. {
  11. // protected $_url = 'http://www.webservicex.net/CurrencyConvertor.asmx/ConversionRate?FromCurrency={{CURRENCY_FROM}}&ToCurrency={{CURRENCY_TO}}';
  12. protected $_url = 'http://www.google.com/ig/calculator?hl=en&q=1{{CURRENCY_TO}}=?{{CURRENCY_FROM}}';
  13. protected $_messages = array();
  14.  
  15. /**
  16.   * HTTP client
  17.   * @var Varien_Http_Client
  18.   */
  19. protected $_httpClient;
  20.  
  21. public function __construct()
  22. {
  23. $this->_httpClient = new Varien_Http_Client();
  24. }
  25.  
  26. protected function _convert($currencyFrom, $currencyTo, $retry=0)
  27. {
  28. $url = str_replace('{{CURRENCY_FROM}}', $currencyFrom, $this->_url);
  29. $url = str_replace('{{CURRENCY_TO}}', $currencyTo, $url);
  30.  
  31. try {
  32. $response = $this->_httpClient
  33. ->setUri($url)
  34. ->setConfig(array('timeout' => Mage::getStoreConfig('currency/webservicex/timeout')))
  35. ->request('GET')
  36. ->getBody();
  37.  
  38. $data = explode('"', $response);
  39. $data = explode(' ', $data[3]);
  40. $return = round($data[0], 5);
  41.  
  42. return $return;
  43. }
  44. catch (Exception $e) {
  45. if( $retry == 0 ) {
  46. $this->_convert($currencyFrom, $currencyTo, 1);
  47. } else {
  48. $this->_messages[] = Mage::helper('directory')->__('Cannot retrieve rate from %s.', $url);
  49. }
  50. }
  51. }
  52. }

Report this snippet  

You need to login to post a comment.