Xin code quy đổi tỷ giá VM 2.0 - Joomla! Forum - community, help and support
theo như mình được biết thì tỷ giá được quy định ở file : convertecb.php (nguồn tỷ giá ở trang http://www.ecb.europa.eu/stats/eurofxre ... -daily.xml )
bạn nào có thể override lại dùm mình file này, sử dụng nguồn tỷ giá ở 1 trong các ngân hàng ở việt nam ( vietcombank chẳng hạn)
mình gà mờ nên ko rành viết code lại trang này để có thể lấy tỷ giá ở các ngân hàng việt nam @@
xin chân thành cám ơn các bạn đã xem & giúp đỡ.
bạn nào có thể override lại dùm mình file này, sử dụng nguồn tỷ giá ở 1 trong các ngân hàng ở việt nam ( vietcombank chẳng hạn)
mình gà mờ nên ko rành viết code lại trang này để có thể lấy tỷ giá ở các ngân hàng việt nam @@
xin chân thành cám ơn các bạn đã xem & giúp đỡ.
có vẻ như xin 1 file code hoàn chỉnh thì hơi căng. thôi thì ai biết cho mình hỏi là :
mình fai override như thế nào để có thể lấy tỷ giá từ ngân hàng việt, chứ ko fai hiện tại là ngân hàng châu Âu.
mình fai override như thế nào để có thể lấy tỷ giá từ ngân hàng việt, chứ ko fai hiện tại là ngân hàng châu Âu.
code: select all
<?php
if( !defined( '_jexec' ) ) die( 'direct access '.basename(__file__).' not allowed.' );
/**
* ecb currency converter module
*
* @version $id: convertecb.php 6172 2012-06-28 07:24:53z milbo $
* @package virtuemart
* @subpackage classes
* @copyright copyright (c) 2004-2008 soeren - rights reserved.
* @license http://www.gnu.org/copyleft/gpl.html gnu/gpl, see license.php
* virtuemart free software. version may have been modified pursuant
* gnu general public license, , distributed includes or
* derivative of works licensed under gnu general public license or
* other free or open source software licenses.
* see /administrator/components/com_virtuemart/copyright.php copyright notices , details.
*
* http://virtuemart.org
*/
/**
* class uses currency rates provided xml file european central bank
* requires curl or allow_url_fopen
*/
class convertecb {
// var $archive = true;
// var $last_updated = '';
var $document_address = 'http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml';
var $info_address = 'http://www.ecb.int/stats/eurofxref/';
var $supplier = 'european central bank';
/**
* converts amount 1 currency using
* rate conversion table european central bank
*
* @param float $amounta
* @param string $curra defaults $vendor_currency
* @param string $currb defaults to
* @return mixed converted amount when successful, false on failure
*/
// function convert( $amounta, $curra='', $currb='', $a2b = true ) {
function convert( $amounta, $curra='', $currb='', $a2rc = true, $relatedcurrency = 'eur') {
// cache subfolder(group) 'convertecb', cache method: callback
$cache= jfactory::getcache('convertecb','callback');
// save configured lifetime
@$lifetime=$cache->lifetime;
$cache->setlifetime(86400/4); // check 4 time per day
// save cache conf
$conf = jfactory::getconfig();
// check if cache enabled in configuration
$cacheactive = $conf->getvalue('config.caching');
$cache->setcaching(1); //enable caching
$globalcurrencyconverter = $cache->call( array( 'convertecb', 'getsetexchangerates' ),$this->document_address );
// revert configuration
$cache->setcaching($cacheactive);
if(!$globalcurrencyconverter ){
//vmdebug('convert convert no $globalcurrencyconverter convert '.$amounta);
return $amounta;
} else {
$vala = isset( $globalcurrencyconverter[$curra] ) ? $globalcurrencyconverter[$curra] : 1.0;
$valb = isset( $globalcurrencyconverter[$currb] ) ? $globalcurrencyconverter[$currb] : 1.0;
$val = (float)$amounta * (float)$valb / (float)$vala;
//vmdebug('convertecb '.$curra.' '.$amounta.' * '.$valb.' / '.$vala.' = '.$val,$globalcurrencyconverter[$curra]);
return $val;
}
}
static function getsetexchangerates($ecb_filename){
$archive = true;
setlocale(lc_time, "en-gb");
$now = time() + 3600; // time in ecb (germany) gmt + 1 hour (3600 seconds)
if (date("i")) {
$now += 3600; // adjust daylight saving time
}
$weekday_now_local = gmdate('w', $now); // week day, important: week starts sunday (= 0) !!
$date_now_local = gmdate('ymd', $now);
$time_now_local = gmdate('hi', $now);
$time_ecb_update = '1415';
if( is_writable(jpath_base.ds.'cache') ) {
$store_path = jpath_base.ds.'cache';
}
else {
$store_path = jpath_site.ds.'media';
}
$archivefile_name = $store_path.'/daily.xml';
$val = '';
if(file_exists($archivefile_name) && filesize( $archivefile_name ) > 0 ) {
// timestamp filename
$file_datestamp = date('ymd', filemtime($archivefile_name));
// check if today weekday - no updates on weekends
if( date( 'w' ) > 0 && date( 'w' ) < 6
// compare filedate , actual date
&& $file_datestamp != $date_now_local
// if localtime greater ecb-update-time go on update , write files
&& $time_now_local > $time_ecb_update) {
$curr_filename = $ecb_filename;
}
else {
$curr_filename = $archivefile_name;
$last_updated = $file_datestamp;
$archive = false;
}
}
else {
$curr_filename = $ecb_filename;
}
if( !is_writable( $store_path )) {
$archive = false;
vmerror( "the file $archivefile_name can't created. directory $store_path not writable" );
}
// jerror::raisenotice(1, "the file $archivefile_name should in directory $store_path " );
if( $curr_filename == $ecb_filename ) {
// fetch file internet
if(!class_exists('vmconnector')) require(jpath_vm_administrator.ds.'helpers'.ds.'connection.php');
// jerror::raisenotice(1, "updating currency " );
if (!$contents = vmconnector::handlecommunication( $curr_filename )) {
if (isset($file_datestamp)) {
$contents = @file_get_contents( $curr_filename );
}
} else $last_updated = date('ymd');
}
else {
$contents = @file_get_contents( $curr_filename );
}
if( $contents ) {
// if archivefile not exist
if( $archive ) {
// write new file
file_put_contents( $archivefile_name, $contents );
}
$contents = str_replace ("<cube currency='usd'", " <cube currency='eur' rate='1'/> <cube currency='usd'", $contents);
/* xml parsing */
$xmldoc = new domdocument();
if( !$xmldoc->loadxml($contents) ) {
//todo
vmerror('failed parse currency converter xml document.');
vmerror('the content: '.$contents);
// $globals['product_currency'] = $vendor_currency;
return false;
}
$currency_list = $xmldoc->getelementsbytagname( "cube" );
// loop through currency list
$length = $currency_list->length;
for ($i = 0; $i < $length; $i++) {
$currnode = $currency_list->item($i);
if(!empty($currnode) && !empty($currnode->attributes->getnameditem("currency")->nodevalue)){
$currency[$currnode->attributes->getnameditem("currency")->nodevalue] = $currnode->attributes->getnameditem("rate")->nodevalue;
unset( $currnode );
}
}
$globalcurrencyconverter = $currency;
}
else {
$globalcurrencyconverter = false;
vmerror( 'failed retrieve currency converter xml document.');
// return false;
}
return $globalcurrencyconverter;
}
}
// pure php no closing tag
Comments
Post a Comment