0

On my website header I have a shopping cart icon with a badge that display the number of the items in the cart. When you enter in the website, it should display 0, as you have no item in the cart. However the badge is empty until you add a item in the cart. But if you later remove all items than it does display 0.

This is my code:

  <span class="badge  badge-inverse">
      <?php echo $this->getSummaryCount();?>                 
  </span>  

How to modify it to always display 0 if there are no items in the cart? I tried to use conditionals but for some reason it doesn't work.

2

try with

<?php echo (int)$this->getSummaryCount();?>

But this theory falls if you have products that can be ordered in fractions. (like qty = 1.3)

  • It works! Thank you very much. I lost a lot of time with this issue. – George Dec 2 '14 at 15:49
  • @George If it works, please mark the answer as accepted. Don't leave any loose ends. – Marius Dec 2 '14 at 15:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.