Changing Cart Image when cart is filled

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
14 years ago
Hi, I like to use 2 images for the cart i.e. empty and full
By default the empty shopping cart image is shown but when any item is added then the cart icon should changed to the one that shows the cart filled.
Any idea how to do that?
14 years ago
do a count on the number of items in the basket. based on this logic, you can choose which image to display.
14 years ago
can u explain with a little more guidance please, I am new to codes and dont have much knowledge
14 years ago
You need to alter this in Header.ascx    

<li><a href="<%=Page.ResolveUrl("~/ShoppingCart.aspx")%>" class="ico-cart">
                    <%=GetLocaleResourceString("Account.ShoppingCart")%>
                </a><a href="<%=Page.ResolveUrl("~/ShoppingCart.aspx")%>">(<%=ShoppingCartManager.GetCurrentShoppingCart(ShoppingCartTypeEnum.ShoppingCart).Count%>)</a>
                </li>

The image has to do with ico-cart so you just need to check whether the count is greater than 0 and change the class accordingly.

Hope this helps.  Thanks,
Matthew
14 years ago
Thanks Matthew
Can you tell me how to check the count and change class accordingly? Sorry I am dumb with codes :(
14 years ago
For a really really dirsty hack in header.ascx you could replace

UNTESTED

     <li><a href="<%=Page.ResolveUrl("~/ShoppingCart.aspx")%>" class="ico-cart">
                    <%=GetLocaleResourceString("Account.ShoppingCart")%>
                </a><a href="<%=Page.ResolveUrl("~/ShoppingCart.aspx")%>">(<%=ShoppingCartManager.GetCurrentShoppingCart(ShoppingCartTypeEnum.ShoppingCart).Count%>)</a>
                </li>


with

       <%if (ShoppingCartManager.GetCurrentShoppingCart(ShoppingCartTypeEnum.ShoppingCart).Count > 0)
                  { %>
                <li><a href="<%=Page.ResolveUrl("~/ShoppingCart.aspx")%>" class="ico-cart-fill">
                    <%=GetLocaleResourceString("Account.ShoppingCart")%>
                </a><a href="<%=Page.ResolveUrl("~/ShoppingCart.aspx")%>">(<%=ShoppingCartManager.GetCurrentShoppingCart(ShoppingCartTypeEnum.ShoppingCart).Count%>)</a>
                </li>
                <%}
                  else
                  { %>
               <li><a href="<%=Page.ResolveUrl("~/ShoppingCart.aspx")%>" class="ico-cart">
                    <%=GetLocaleResourceString("Account.ShoppingCart")%>
                </a><a href="<%=Page.ResolveUrl("~/ShoppingCart.aspx")%>">(<%=ShoppingCartManager.GetCurrentShoppingCart(ShoppingCartTypeEnum.ShoppingCart).Count%>)</a>
                </li>
                <%} %>


then create a new class in master.css like

.header .ico-cart-fill
{
  background: url('images/ico-cart-fill.gif') no-repeat;
  padding-left: 20px;
  padding-bottom: 5px;
}
14 years ago
Thanks Matthew, you are a great ... it worked
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.