货币转换器virtuemart

时间:2013-06-14 12:51:58

标签: php joomla joomla2.5 virtuemart

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

我是越南人,我想将越南盾率添加到货币转换器。 我使用来自越南对外贸易联合股份银行(Vietcombank)的文件XML将EUR转换为VND 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 */

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

1 个答案:

答案 0 :(得分: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);