function uc_cart_get_total_qty in Ubercart 7.3
Same name and namespace in other branches
- 6.2 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
int An integer representing the total number of items in the cart.
1 call to uc_cart_get_total_qty()
- UbercartCartCheckoutTestCase::testDeletedCartItem in uc_cart/
tests/ uc_cart.test - Tests that cart automatically removes products that have been deleted.
File
- uc_cart/
uc_cart.module, line 1092
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;
}