function commerce_cart_order_empty in Commerce Core 7
Deletes every product line item from a shopping cart order.
Parameters
$order: The shopping cart order to empty.
Return value
The order with the product line items all removed.
1 call to commerce_cart_order_empty()
- commerce_cart_rules_empty in modules/
cart/ commerce_cart.rules.inc - Rules action: empties a cart order.
File
- modules/
cart/ commerce_cart.module, line 1525 - Implements the shopping cart system and add to cart features.
Code
function commerce_cart_order_empty($order) {
$order_wrapper = entity_metadata_wrapper('commerce_order', $order);
// Build an array of product line item IDs.
$line_item_ids = array();
foreach ($order_wrapper->commerce_line_items as $delta => $line_item_wrapper) {
$line_item_ids[] = $line_item_wrapper->line_item_id
->value();
}
// Delete each line item one by one from the order. This is done this way
// instead of unsetting each as we find it to ensure that changing delta
// values don't prevent an item from being removed from the order.
foreach ($line_item_ids as $line_item_id) {
$order = commerce_cart_order_product_line_item_delete($order, $line_item_id, TRUE);
}
// Allow other modules to update the order on empty prior to save.
module_invoke_all('commerce_cart_order_empty', $order);
// Save and return the order.
commerce_order_save($order);
return $order;
}