nitems — return the total number of items in the electronic cart


Attribute Pos. Req. Default Description
name Yes Yes main Cart name.
lines 0 Whether to show the number of lines in the cart instead of the sum of the items.
qualifier An item attribute that must evaluate to a true value, in order for the item to be counted.
compare Instead of counting items based solely on item attribute "trueness" (as qualifier= does by default), perform the specified regular expression pattern matching on the qualifier= attribute.
interpolate     0 interpolate output?
hide     0 Hide the tag return value?


The tag returns the total number of items in users' electronic cart.


This tag does not appear to be affected by, or affect, the rest of Interchange.


Example: Basic example

You have [nitems] items in your cart.



nitems is available in Interchange versions:

4.6.0-5.9.0 (git-head)


Interchange 5.9.0:

Source: code/SystemTag/nitems.coretag
Lines: 14

# Copyright 2002-2007 Interchange Development Group and others
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.  See the LICENSE file for details.
# $Id: nitems.coretag,v 1.5 2007-03-30 23:40:49 pajamian Exp $

UserTag nitems              Order        name
UserTag nitems              addAttr
UserTag nitems              PosNumber    1
UserTag nitems              Version      $Revision: 1.5 $
UserTag nitems              MapRoutine   Vend::Util::tag_nitems

Source: lib/Vend/
Lines: 1501

sub tag_nitems {
my($ref, $opt) = @_;
  my($cart, $total, $item);

if($ref) {
   $cart = $::Carts->{$ref}
     or return 0;
else {
  $cart = $Vend::Items;

my ($attr, $sub);
if($opt->{qualifier}) {
  $attr = $opt->{qualifier};
  my $qr;
  eval { 
    $qr = qr{$opt->{compare}} if $opt->{compare};
  if($qr) {
    $sub = sub { 
            $_[0] =~ $qr;
  else {
    $sub = sub { return $_[0] };

if($opt->{lines}) {
  return scalar(grep {! $attr or $sub->($_->{$attr})} @$cart);

  $total = 0;
  foreach $item (@$cart) {
  next if $attr and ! $sub->($item->{$attr});

              if ($opt->{gift_cert} && $item->{$opt->{gift_cert}}) {

  $total += $item->{'quantity'};


Interchange Development Group


DocBook! Interchange!