You are here

function uc_cart_empty in Ubercart 6.2

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

Empties a cart of its contents.

Parameters

$cart_id: The ID of the cart.

$op: The $op parameter to pass to hook_cart_item(), if not the default 'remove'.

5 calls to uc_cart_empty()
UbercartCartCheckoutTestCase::testCartAPI in uc_cart/uc_cart.test
uc_2checkout_complete in payment/uc_2checkout/uc_2checkout.pages.inc
@file 2checkout menu items.
uc_cart_complete_sale in uc_cart/uc_cart.module
Completes a sale, including adjusting order status and creating user account.
uc_cart_cron in uc_cart/uc_cart.module
Implements hook_cron().
uc_cart_links_process in uc_cart_links/uc_cart_links.pages.inc
Process a cart link to fiddle with the cart and redirect the user.

File

uc_cart/uc_cart.module, line 1646

Code

function uc_cart_empty($cart_id, $op = 'remove') {
  if (is_null($cart_id) || empty($cart_id)) {
    return;
  }

  // Empty cart one item at a time.  This will ensure the cart_item hook is fired with $op set to 'remove' for each item.
  $items = uc_cart_get_contents($cart_id);
  foreach ($items as $item) {
    uc_cart_remove_item($item->nid, $cart_id, $item->data, $op);
  }

  // Probably don't need this query, but it will ensure anything not removed with the above loop is removed here.
  db_query("DELETE FROM {uc_cart_products} WHERE cart_id = '%s'", $cart_id);

  // Remove cached cart.
  uc_cart_get_contents($cart_id, 'rebuild');
}