String 38
Code: Select all
return $value * ($to / $from);
Code: Select all
weights[$from]
Fix is easy: just add after string 29
Code: Select all
return 0;
Code: Select all
return $value * ($to / $from);
Code: Select all
weights[$from]
Code: Select all
return 0;
Code: Select all
if (!isset($this->weights[$from]) || !isset($this->weights[$to])) {
return $value;
} else {
$from = $this->weights[$from]['value'];
$to = $this->weights[$to]['value'];
return $value * ($to / $from);
}
Code: Select all
if (isset($this->weights[$from])) {
$from = $this->weights[$from]['value'];
} else {
$from = 0;
}
if (isset($this->weights[$to])) {
$to = $this->weights[$to]['value'];
} else {
$to = 0;
}
return $value * ($to / $from);
If added your code, we gotPHP Warning: Division by zero in ******\PHP\htdocs\online\system\library\weight.php on line 38
So, currently we still use the old version of weight.phpWarning: No Shipping options are available. Please contact us for assistance!
I know nothing about PHP and SQL, but I still try my best to understand it.
i tried this, but while it avoids the error message, it still fails to realise the cart's weight, which means weight based shipping calculation isn't accurate.DaneSoul wrote:Fix is easy: just add after string 29Code: Select all
return 0;
Code: Select all
<?php
class Weight {
private $weights = array();
public function __construct($registry) {
$this->db = $registry->get('db');
$this->config = $registry->get('config');
$weight_class_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "weight_class wc LEFT JOIN " . DB_PREFIX . "weight_class_description wcd ON (wc.weight_class_id = wcd.weight_class_id) WHERE wcd.language_id = '" . (int)$this->config->get('config_language_id') . "'");
foreach ($weight_class_query->rows as $result) {
$this->weights[$result['weight_class_id']] = array(
'weight_class_id' => $result['weight_class_id'],
'title' => $result['title'],
'unit' => $result['unit'],
'value' => $result['value']
);
}
}
public function convert($value, $from, $to) {
if ($from == $to) {
return $value;
}
if (isset($this->weights[$from])) {
$from = $this->weights[$from]['value'];
} else {
$from = 0;
}
if (isset($this->weights[$to])) {
$to = $this->weights[$to]['value'];
} else {
$to = 0;
}
return $value * ($to / $from);
}
public function format($value, $weight_class_id, $decimal_point = '.', $thousand_point = ',') {
if (isset($this->weights[$weight_class_id])) {
return number_format($value, 2, $decimal_point, $thousand_point) . $this->weights[$weight_class_id]['unit'];
} else {
return number_format($value, 2, $decimal_point, $thousand_point);
}
}
public function getUnit($weight_class_id) {
if (isset($this->weights[$weight_class_id])) {
return $this->weights[$weight_class_id]['unit'];
} else {
return '';
}
}
}
?>
This is the solution. Well it also worked for me. Use the Export/Import tool (http://www.opencart.com/index.php?route ... t%20export) to quickly add some values for the weight, length, height, width for all products to fix this issue.ralphstirrat wrote:I finally resolved this problem by making sure all my products had a weight AND a measurement besides them (kg)
works fine now
Code: Select all
public function convert($value, $from, $to) {
if (($from*$to)==0) {
return 0;
}
if ($from == $to) {
return $value;
}
if (isset($this->weights[$from])) {
$from = $this->weights[$from]['value'];
} else {
$from = 0;
}
if (isset($this->weights[$to])) {
$to = $this->weights[$to]['value'];
} else {
$to = 0;
}
return $value * ($to / $from);
}
I just found exactly the same error, when playing around with my latest OC v.1.5.6.4/v.1.5.6.5_rc-Version.m3xp2013 wrote:I finally resolved this problem:
Code: Select all
public function convert($value, $from, $to) {
if ($from == $to) {
return $value;
}
if (isset($this->weights[$from])) {
$from = $this->weights[$from]['value'];
} else {
$from = 0;
}
if (isset($this->weights[$to])) {
$to = $this->weights[$to]['value'];
} else {
$to = 0;
}
if($from == 0)
return $value;
return @($value * ($to / $from));
}
My Github OC Site: https://github.com/IP-CAM
5'200 + FREE OC Extensions, on the World's largest private Github OC Repository Archive Site.
Users browsing this forum: Google [Bot] and 36 guests