Smarty variable to check if cart is empty or not

Hi guys,



If anyone here have any idea to where to fine smarty variable to check whether the cart is empty or not?



I added an icon on the top menu and I wanted to change the icon depending on whether the cart is empty or not. I tried writing a js code on the template hook I created (topmenu_dropdown.override.tpl). But the variable cart_item is still 0 after I added an item to the cart. I only gains a value when I navigate to other pages thus changing the icon on the top menu. Maybe I dealing with a wrong variable. Anyone can help me on this? Please…



{/literal}

Inside your container, you could easily add dynamic classes to your elements…



EG, for a menu.



  • link with different classes depending on cart contents

  • another link

  • yet another link



You would then simply change the CSS background styles for 'cart-full' and 'cart-empty' to change the icons.

thank for your help. I think that is the smarter way of doing it. It saved me from several lines of codes.



However, the problem is still there. When I tried to put an item on the cart, the icon only changes when I navigate to other pages. It doesn't change automatically after I add an item to my cart.

Which version of the cart are you using and are you using the Ajax add to cart (Settings>Dynamic HTML)?

i am using CS-Cart: version 3.0.3 ULTIMATE.

yes I am using Ajax add to cart.

anybody could help me on this? Your help will be very much appreciated! :-)

This can be the worst way but it does the magic :grin:


<br />
<div id="cart_status_{$dropdown_id}"><br />
{hook name="wrapper:onclick_dropdown_title"}<br />
{if $smarty.session.cart.amount}<br />
<div style="height:200px; width:200px; position:absolute; background:black; z-index:500;">full</div><br />
{else}<br />
<div style="height:200px; width:200px; position:absolute; background:yellow; z-index:500;">empty</div><br />
{/if}<br />
{/hook}</div><br />

You don't see your icon because the add to cart action is an ajax request and the div that contains your icon is not part of the ajax response_ids.

@tblrnseth, do you have any idea how can I include it to ajax response_id?

The way cs-cart ajax is implemented (though I'm certainly NOT an ajax expert by any means), you need to find the form variable for result_ids and add the containing div id attribute to the comma separated list of id's. When the page is rendered on the server it sends the whole thing back (waste of data and processing) and then javascript in the browser walks through what was sent and throws away everything that's not listed in the result_id's. it then takes each of these and replaces the HTML within the container with the new content. Then it finally closes the “Loading” box.