<?php
/**
* @package HikaShop for Joomla!
* @version 1.4.3
* @author hikashop.com
* @copyright (C) 2010 HIKARI SOFTWARE. All rights reserved.
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
*/
defined('_JEXEC') or die('Restricted access');
?>
<?php
class hikashopWeightHelper{
var $conversion = array(
'g'=>array('kg'=>0.001,'lb'=>0.00220462234,'oz'=>0.035273962),
'kg'=>array('g'=>1000,'lb'=>2.20462234,'oz'=>35.273962),
'lb'=>array('kg'=>0.45359237,'g'=>453.59237,'oz'=>16),
'oz'=>array('kg'=>28349.523125,'g'=>28.349523125,'lb'=>0.0625)
);
function hikashopWeightHelper(){
$this->getSymbol();
}
function convert($weight,$symbol_used='',$target=''){
if(empty($target)){
$target=$this->main_symbol;
}
if(empty($symbol_used)){
$symbol_used=$this->main_symbol;
}
if($symbol_used != $target){
$convert = $this->conversion[$symbol_used][$target];
return $weight*$convert;
}
return $weight;
}
function getSymbol(){
if(empty($this->main_symbol)){
$config =& hikashop::config();
$this->symbols = explode(',',$config->get('weight_symbols','kg,g'));
foreach($this->symbols as $k => $symbol){
$this->symbols[$k] = trim($symbol);
}
$this->main_symbol = array_shift($this->symbols);
}
return $this->main_symbol;
}
}