3
I have the following code:
<?php var_dump($fullprice) ?>
<?php var_dump($cart->getData('subtotal')) ?>
<?php var_dump($fullprice == $cart->getData('subtotal')) ?>
$fullprice
returns the sum of all products and quantities in the cart.$cart->getData('subtotal')
returns the subtotal in the cart.
The result:
float(319.2)
float(319.2)
bool(false)
Why this? The 2 values are equal, at least they were printed equal, but the dump returns false
?
Edit: The whole code here
<?php /*---------- ##HACK## ----------*/?>
<?php $cart = Mage::getModel('checkout/cart')->getQuote(); ?>
<?php $fullprice = 0; ?>
<?php foreach ($cart->getAllVisibleItems() as $item): ?>
<?php $fullprice += ($item->getProduct()->getPrice() * $item->getQty()); ?>
<?php endforeach; ?>
<?php var_dump($fullprice) ?>
<br>
<?php var_dump($cart->getData('subtotal')) ?>
<br>
<?php var_dump($fullprice == $cart->getData('subtotal')) ?>
<?php if ($fullprice - $cart->getData('subtotal') > 0): ?>
<p style="color: #319e49; font-size: 16px;">
<?php echo "Você economizou R$", number_format($fullprice - $cart->getData('subtotal'), 2, ',', ''), "</br>" ?>
</p>
<?php endif; ?>
<?php /*---------- ##/HACK## ----------*/?>
Can you create an example with this incorrect result? seems to have something else interfering with the code.
– rray
$fullprice
is an array? by the description you gave in the question it seems that this variable 'does' two things.– rray
I put the full code, take a look
– wdarking
If you did it
echo $cart->getData('subtotal') .'<br>'; echo $cart->getData('subtotal');
the same value is displayed?– rray
I smell places not displayed with different values. You see 319.2, but the computer should see anything like 319.2 billion billion times vs. 319.2 billion billion years ago. Round to two decimal places (or as many needed pro as you want) when comparing non-whole types.
– Oralista de Sistemas
@rray returned:
319.2
319.2
float(319.2) 
float(319.2) 
bool(false)
, the first 2 results referring to the code you recommended– wdarking
Uses a number_format Set to display a 50 houses you will see why. : D
– Guilherme Lautert