带有google convertor URL的magento webservicex

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了带有google convertor URL的magento webservicex相关的知识,希望对你有一定的参考价值。

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. }

以上是关于带有google convertor URL的magento webservicex的主要内容,如果未能解决你的问题,请参考以下文章

Spring类型转换 ConversionSerivce Convertor

JSPatch Convertor 实现原理详解

python: 带有 BeautifulSoup 的 Google 搜索刮板

SAP Hybris的Convertor, Populator, Facade和DTO这几个概念是如何协同工作的

Implant Json Convertor for Entity Framework db first Class

在 Twitter 上共享带有查询字符串的 URL