Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Cart miscalculation
 
Karl456
Jr. Member
 
Total Posts:  28
Joined:  2013-01-10
 

Hello,

I’ve created a new block called topcart in order to change the way the cart is in the header, however I’ve come across an issue in the way Magento calculates the items in the basket and the total price.

Here’s my code:

<?php if ($this->getIsNeedToDisplaySideBar()):?>
    <?php 
        $_cartQty 
$this->getSummaryCount(); 
        
$url $this->getUrl('checkout/cart');
    
?>
    
<a href="<?php echo $url; ?>">
        <
span class="topcart">
            <
span class="basket">
                <
class="amount">
                    
<?php 
                        
if($_cartQty == 0{
                            
echo '0';
                        
else {
                            
echo $this->__('%s'$_cartQty);
                        
}
                    ?>
                
</p>
            </
span>
            <
span class="subtotal">
                  <
span class="label"><?php echo $this->__('Your Cart'?> (<?php echo Mage::helper('checkout')->formatPrice($this->getSubtotal()) ?>)</span
            </
span>
        </
span>
    </
a>
<?php endif;?>

The problem starts on the homepage and all other pages excluding the checkout page.

With extreme values, let’s say 99999999 Ottoman’s from the sample data at £299.99 each, the total price is £29,998,999,700.01.

These two values are displayed correctly in the top cart, however, when I go to the homepage the values change, for no reason.

The Cart Quantity stays the same, but the total price becomes £100,000,000.00.

Then, if you add another item, let’s say a chair for £129.99, the total price and quantity is correct on the cart page. But on the homepage and other pages the quantity becomes 99999999.9999 and the total price becomes £100,000,000.00. which are not correct.

Has anyone else experienced an issue like this with extreme variables?

Regards,
Karl

 
Magento Community Magento Community
Magento Community
Magento Community
 
Karl456
Jr. Member
 
Total Posts:  28
Joined:  2013-01-10
 

I’ve fixed the quantity issue that I was having by using:

__(Mage::getSingleton('checkout/session')->getQuote()->getItemsSummaryQty())

instead of:

$this->__('%s'$_cartQty)

Still no luck on the total price though.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Karl456
Jr. Member
 
Total Posts:  28
Joined:  2013-01-10
 

There seems to be an issue with $this->getSubtotal(); since without any number formatting it returns 99999999.9999, anyone know where I can find this function?

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top