1
我有一個多貨幣的magento商店。產品價格根據IP地址以相關貨幣顯示。 我想爲美國客戶設置英鎊作爲默認貨幣,而不是美元(按照IP地址),美國客戶應該以英鎊顯示價格。如何將美元客戶的英鎊設定爲默認貨幣?
我是新的magento,任何幫助將不勝感激。
我有一個多貨幣的magento商店。產品價格根據IP地址以相關貨幣顯示。 我想爲美國客戶設置英鎊作爲默認貨幣,而不是美元(按照IP地址),美國客戶應該以英鎊顯示價格。如何將美元客戶的英鎊設定爲默認貨幣?
我是新的magento,任何幫助將不勝感激。
我有創造這個作品,你可以試試這個...
第一步:下app/code/local/Amit/AutoCurrency/etc/config.xml
<?xml version="1.0"?>
<config>
<modules>
<Amit_AutoCurrency>
<version>1.0.0</version>
</Amit_AutoCurrency>
</modules>
<global>
<models>
<core>
<rewrite>
<store>Amit_AutoCurrency_Model_Store</store>
</rewrite>
</core>
</models>
<helpers>
<autocurrency>
<class>Amit_AutoCurrency_Helper</class>
</autocurrency>
</helpers>
</global>
</config>
在store.php創建config.xml中爲應用程序/代碼/本地/阿米特/AutoCurrency/Model/Store.php
<?php
class Amit_AutoCurrency_Model_Store extends Mage_Core_Model_Store
{
/**
* Update default store currency code
*
* @return string
*/
public function getDefaultCurrencyCode()
{
$result = $this->getConfig(Mage_Directory_Model_Currency::XML_PATH_CURRENCY_DEFAULT);
return $this->getCurrencyCodeByIp($result);
}
/**
* Get Currency code by IP Address
*
* @return string
*/
public function getCurrencyCodeByIp($result = '')
{
// load GeoIP binary data file
$geoIp = Mage::helper('autocurrency')->loadGeoIp();
$ipAddress = Mage::helper('autocurrency')->getIpAddress();
// get country code from ip address
$countryCode = geoip_country_code_by_addr($geoIp, $ipAddress);
if($countryCode == '') {
return $result;
}
// get currency code from country code
$currencyCode = geoip_currency_code_by_country_code($geoIp, $countryCode);
// close the geo database
geoip_close($geoIp);
// if currencyCode is not present in allowedCurrencies
// then return the default currency code
$allowedCurrencies = Mage::getModel('directory/currency')->getConfigAllowCurrencies();
if(!in_array($currencyCode, $allowedCurrencies)) {
if($currencyCode="USD"){
return "GBP";
}
return $result;
}
if($currencyCode="USD"){
return "GBP";
}
return $currencyCode;
}
}
和幫助功能是應用程序/代碼/本地/艾米特/ AutoCurrency /助手/ Data.php
<?php
class Amit_AutoCurrency_Helper_Data extends Mage_Core_Helper_Abstract
{
/**
* Load GeoIP binary data file
*
* @return string
*/
public function loadGeoIp()
{
// Load geoip.inc
include_once(Mage::getBaseDir().'/var/geoip/geoip.inc');
// Open Geo IP binary data file
$geoIp = geoip_open(Mage::getBaseDir().'/var/geoip/GeoIP.dat',GEOIP_STANDARD);
return $geoIp;
}
/**
* Get IP Address
*
* @return string
*/
public function getIpAddress()
{
//return "124.41.230.51";
return $_SERVER['REMOTE_ADDR'];
}
}
應用程序的/ etc /模塊/ Amit_AutoCurrency.php
<?xml version="1.0"?>
<config>
<modules>
<Amit_AutoCurrency>
<active>true</active>
<codePool>local</codePool>
</Amit_AutoCurrency>
</modules>
</config>
下載geoip的文件去
https://github.com/maxmind/geoip-api-php
我希望這將是對你的工作
非常感謝阿米特。您能否告訴我如何爲英國和美國客戶設置默認貨幣英鎊?我已經添加了上述文件,但即使對於英國客戶,默認貨幣仍然以美元計算。 – user3469531
geoip_currency_code_by_country_code功能不起作用。爲什麼? –