You are here

function uc_cart_get_total_qty in Ubercart 6.2

Same name and namespace in other branches
  1. 7.3 uc_cart/uc_cart.module \uc_cart_get_total_qty()

Returns the total number of items in the shopping cart.

The total number of items in the cart isn't simply queried directly from the database, because when the shopping cart is loaded items may in fact be altered or removed. Hence we actually load the cart and tally up the total number of items from the fully loaded cart instead.

Parameters

$cid: The cart ID of the shopping cart whose items we're totalling; defaults to the current user's cart.

Return value

An integer representing the total number of items in the cart.

1 call to uc_cart_get_total_qty()
UbercartCartCheckoutTestCase::testDeletedCartItem in uc_cart/uc_cart.test

File

uc_cart/uc_cart.module, line 1420

Code

function uc_cart_get_total_qty($cid = NULL) {
  $qty = 0;
  if (empty($cid)) {
    $cid = uc_cart_get_id(FALSE);
  }
  if ($cid) {
    foreach (uc_cart_get_contents($cid) as $item) {
      $qty += $item->qty;
    }
  }
  return $qty;
}