Welcome Guest, Not a member yet? Register   Sign In
The cart class messes up with free products
#1

[eluser]Unknown[/eluser]
I'm fairly new to CI, and may or may not have found a bug. Specifically, free products with a price of 0.00 do not display when you try to display the cart total or subtotal as shown in the user manual.

For example, the example in the user manual displays the cart subtotal using:

Code:
<?php echo $this->cart->format_number($items['subtotal']); ?>

If you put 0.00 (i.e., a free product) into that, the subtotal does not display. The same happens with the total. I opened system/libraries/Cart.php and in the format_number() function, I changed this:

Code:
if ($n == '')
{
    return '';
}

to this:

Code:
if ($n == '' && $n !== 0.00)
{
     return '';
}

After making that change, the subtotal and total display properly with values of 0.00.

Is this by design, or is it a bug?
#2

[eluser]Unknown[/eluser]
Actually, this works too (with === instead of ==)...

Code:
if ($n === '')
{
     return '';
}

Which method is "better"?




Theme © iAndrew 2016 - Forum software by © MyBB