如何将英镑设置为magento中美国客户的默认货币



我有一个带有多种货币的magento商店。产品价格根据IP地址以相关货币显示。我想将英镑设置为美国客户的默认货币,即美国客户的价格应该以英镑显示,而不是美元(根据ip地址)。

我是新来的magento,任何帮助将不胜感激。

我已经为这个作品创建了一个,你可以试试这个…

Step1:在app/code/local/Amit/AutoCurrency/etc/config.xml

下创建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中是app/code/local/Amit/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;
    }
}

帮助函数为app/code/local/Amit/AutoCurrency/Helper/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

我希望这对你有用

最新更新