Coding Tips: November 2007 Archives

This code can be used on the display the total number of items that are in a cart. For example, if the cart contains five of one line item, and three of another line item, this code would display Total items in cart: 8.


<ss:set name="math" value="$system.getMath('0')"/>
<ss:foreach item="detail" within="$cart.details">
  <ss:directive source="$math.set($math.add($detail.quantity))"/>
</ss:foreach>
Total items in cart: <ss:value source="$math.get()"/>

If you use this code on the Cart template, you can just add the ss:set tag before the existing ss:foreach, add the ss:directive tag anywhere within the ss:foreach, and then add the Total Quantity line to the end (after the close ss:foreach).

About this Archive

This page is an archive of blog entries in the Coding Tips category from November 2007.

Coding Tips: April 2007 is the previous archive.

Coding Tips: February 2008 is the next archive.

Find recent content on the main index or look in the archives to find all content.