0

I'm using a badge icon to display the number of cart items. It works great when the number is 1 or more but if there are no items in the cart, it doesn't display zero, but rather half of it disappears. I've posted screenshots of what it looks like with a value of 1+ and then what it looks like when the cart is empty. Further, even after an item is added to the cart, the badge doesn't pop up with the number until refreshing or going to the next page after the item has been added.

I'm thinking I probably have to add more script but just learning and not sure how I would do this.

To give the full picture: This is a BigCommerce site so the cart info is generated by an internal server. It is referenced by variable %%GLOBAL_CartItems%% (in code below) and normally displays as a text string, "View Cart.." along with the total number of items in the cart. Since I only want the number, I added script that replaces the text with numeric values only. I've included both the HTML and script below.

What it looks like with 1 or more in cart:

enter image description here

What it looks like with no items in cart:

enter image description here

<li style="display:%%GLOBAL_HideCartOptions%%">
    <span><a href="%%GLOBAL_ShopPathNormal%%/cart.php" title="%%LNG_ViewCart%%"><i class="icon-large sprite-glyphicons_halflings_115_shopping-cart2x icon-2x" style="position: relative; top: 14px; right: 16px;"></i><span id='cart-items' class="badge badge-info" style="position: relative; top: 18px; right: 17px;">%%GLOBAL_CartItems%%</span></a></span>
</li>

<script type='text/javascript'>
   var $cart_items = $('#cart-items');
   $cart_items.text($cart_items.text().replace(/[^0-9]/g, ''));
</script>

Badge CSS:

.badge {
  padding: 1px 9px 2px;
  font-size: 10.998px;
  font-weight: bold;
  line-height: 14px;
  color: #ffffff;
  vertical-align: baseline;
  white-space: nowrap;
  text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.25);
  background-color: #999999;
  -webkit-border-radius: 9px;
  -moz-border-radius: 9px;
  border-radius: 9px;
}
Zipotontic
  • 508
  • 1
  • 5
  • 15
  • Why it's moved on the right? Is there something else (more) on its left that _pushes_
  • too much (and it's clipped)? from your code it's hard to say...
  • – Adriano Repetti Oct 22 '13 at 10:57
  • I thought about this as well. I don't think it's what is the issue however. I've tried to move it around and it still looks the same. I think it's something having to do with the way I've had to force displaying only the number portion of the BigCommerce global CartItems variable. Maybe it's trying to hide when the number is 0 or less but BigCommerce is generating 'View Cart' preventing it from hiding all the way....? – Zipotontic Oct 22 '13 at 20:21