我尝试使用一个类来转换重量,kg in gr .... 但我总是喜欢价值。
public function prepareRules() {
$Db = Registry::get('Db');
$Language = Registry::get('Language');
$Qrules = $CLICSHOPPING_Db->prepare('select r.weight_class_from_id,
r.weight_class_to_id,
r.weight_class_rule
from :table_weight_classes_rules r,
:table_weight_classes c
where c.weight_class_id = r.weight_class_from_id
');
$Qrules->setCache('weight-rules');
$Qrules->execute();
while ( $Qrules->fetch() ) {
$this->weight_classes[$Qrules->valueInt('weight_class_from_id')][$Qrules->valueInt('weight_class_to_id')] = $Qrules->value('weight_class_rule');
}
$Qclasses = $Db->prepare('select weight_class_id,
weight_class_key,
weight_class_title
from :table_weight_classes
where language_id = :language_id
');
$Qclasses->bindInt(':language_id', $Language->getID());
$Qclasses->execute();
while ( $Qclasses->fetch() ) {
$this->weight_classes[$Qclasses->valueInt('weight_class_id')]['key'] = $Qclasses->value('weight_class_key');
$this->weight_classes[$Qclasses->valueInt('weight_class_id')]['title'] = $Qclasses->value('weight_class_title');
}
}
public function convert($value, $unit_from, $unit_to) {
if ( $unit_from == $unit_to ) {
$convert = number_format($value, $this->precision, static::getNumericDecimalSeparator(), static::getNumericThousandsSeparator());
return $convert;
} else {
$convert = number_format($value * $this->weight_classes[(int)$unit_from][(int)$unit_to], $this->precision, static::getNumericDecimalSeparator(), static::getNumericThousandsSeparator());
return $convert;
}
如果我尝试转换某些东西 $ products_weight = $ Weight-> convert(5,2,3);
5是重量(值)
2是kg($ unit_from)
3是oz($ unit_to)
var_dump($value); ==> ok
var_dump($this->weight_classes[(int)$unit_from][(int)$unit_to]); ==> always 0