Post by Qphoria » Tue Aug 04, 2009 4:43 am

This is another case where the function does more than it should.

There are 2 functions in the weight library class.
one is for converting
one is for formatting

The conversion one should expect a numeric value input and return a numeric value.
The format function should expect a numeric value input and return a string value.

But the convert function adds number_formatting with the thousand_point, which in essence returns a string.
So if you want to convert a 1000 kg product into lbs, the convert will take "1000" and return "2,204".
The comma is then assumed to be a string so when the $cart->getWeight() function tries to += that returned value, it will only use the first "2" and truncate the rest. So 1000kg becomes 2lbs which is very wrong.

The convert function should only handle the numeric conversion. This also simplifies the function:

Code: Select all

public function convert($value, $from, $to) {
	if ($from != $to) { $value=($value * (float)$this->rules[$from][$to]); }
	return $value;
}
This won't break any calls to this function as there was only a call from the cart library and the cart model, both from the getWeight function and both only supplying the value, from, and to

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by Qphoria » Wed Aug 05, 2009 4:13 am

Daniel did you get a chance to review this one?

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by Daniel » Wed Aug 05, 2009 4:20 am

yes. i think it was fixed in the last version.

OpenCart®
Project Owner & Developer.


User avatar
Administrator

Posts

Joined
Fri Nov 03, 2006 6:57 pm

Post by Qphoria » Wed Aug 05, 2009 4:21 am

Ah you are right. Sorry

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am
Who is online

Users browsing this forum: No registered users and 11 guests