0

我在 ECBconverter 中配置自动更新汇率有一个严重问题

我是越南人,我想将越南盾汇率添加到货币转换器。我使用越南外贸股份商业银行 (Vietcombank) 的文件 XML 将欧元转换为越南盾 http://www.vietcombank.com.vn/ExchangeRates/ExrateXML.aspx

之前,我使用 Virtuemart 1.x 并在 ECBconverter.php 中添加更多代码。所以,没关系。没问题。

                // now write new file
                file_put_contents( $archivefile_name, $contents );
            }


          //code get exchange rate from vietcombank
            $Link = new SimpleXMLElement('http://www.vietcombank.com.vn/ExchangeRates/ExrateXML.aspx',NULL,true);
            foreach($Link->Exrate as $Exrate)
            {
            if ($Exrate['CurrencyCode']=="EUR") $tigia = $Exrate['Sell'];
            }
            //Add exchange rate VND-EUR into xml file
            $contents = str_replace ("<Cube currency='USD'", " <Cube currency='EUR' rate='1'/><Cube currency='VND' rate='".$tigia."'/> <Cube currency='USD'", $contents);



            /* XML Parsing */

但是,现在使用 Virtuemart 2.x。我将此代码添加到 ECBconverter.php 中它不起作用!我不知道为什么?

           // now write new file
           file_put_contents( $archivefile_name, $contents );
        }


    //code get exchange rate from vietcombank
            $Link = new SimpleXMLElement('http://www.vietcombank.com.vn/ExchangeRates/ExrateXML.aspx',NULL,true);
            foreach($Link->Exrate as $Exrate)
            {
            if ($Exrate['CurrencyCode']=="EUR") $tigia = $Exrate['Sell'];
            }
            //Add exchange rate VND-EUR into xml file
            $contents = str_replace ("<Cube currency='USD'", " <Cube currency='EUR' rate='1'/><Cube Currency='VND' rate='".$tigia."'/> <Cube currency='USD'", $contents);




        /* XML Parsing */

有人帮助我:(我非常非常需要你的帮助!谢谢大家。

4

1 回答 1

0

以下与 Virtuemart2 相关。

在大多数情况下,您只需转换为默认的商店货币,然后让 Virtuemart 从那里处理它。Virtuemart 将根据用户选择的货币转换和显示商店货币。

执行以下操作:

如果您知道currency_code ...

    $amount_in_shop_currency = convertToShopCurrency($amount_in_AUD, 'AUD');

    function convertToShopCurrency($amount, $currency_code)
    {
            if (!$currency_code)
                    return $amount;
            $dbo = JFactory::getDBO();
            $dbo->setQuery("SELECT virtuemart_currency_id FROM #__virtuemart_currencies WHERE currency_code_3 = '{$currency_code}' LIMIT 1");
            $currency_id = $dbo->loadResult();
            if (!$currency_id)
                    return $amount;
            if (!class_exists('CurrencyDisplay'))
                    require(JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'currencydisplay.php');
            $currency = CurrencyDisplay::getInstance();
            return $currency->convertCurrencyTo($currency_id, $amount);
    }

...或者如果您已经知道货币 ID ...

            if (!class_exists('CurrencyDisplay'))
                    require(JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'currencydisplay.php');
            $currency = CurrencyDisplay::getInstance();
            $amount_in_shop_currency =  $currency->convertCurrencyTo($convert_from_currency_id, $convert_from_amount);
于 2013-10-31T02:02:39.817 回答