You are here

function commerce_cart_order_product_line_item_delete in Commerce Core 7

Deletes a product line item from a shopping cart order.

Parameters

$order: The shopping cart order to delete from.

$line_item_id: The ID of the product line item to delete from the order.

$skip_save: TRUE to skip saving the order after deleting the line item; used when the order would otherwise be saved or to delete multiple product line items from the order and then save.

Return value

The order with the matching product line item deleted from the line item reference field.

4 calls to commerce_cart_order_product_line_item_delete()
commerce_cart_order_empty in modules/cart/commerce_cart.module
Deletes every product line item from a shopping cart order.
commerce_cart_order_refresh in modules/cart/commerce_cart.module
Refreshes the contents of a shopping cart by finding the most current prices for any product line items on the order.
commerce_line_item_handler_field_edit_delete::views_form_submit in modules/line_item/includes/views/handlers/commerce_line_item_handler_field_edit_delete.inc
commerce_line_item_handler_field_edit_quantity::views_form_submit in modules/line_item/includes/views/handlers/commerce_line_item_handler_field_edit_quantity.inc

File

modules/cart/commerce_cart.module, line 1488
Implements the shopping cart system and add to cart features.

Code

function commerce_cart_order_product_line_item_delete($order, $line_item_id, $skip_save = FALSE) {
  $line_item = commerce_line_item_load($line_item_id);

  // Check to ensure the line item exists and is a product line item.
  if (!$line_item || !in_array($line_item->type, commerce_product_line_item_types())) {
    return $order;
  }

  // Remove the line item from the line item reference field.
  commerce_entity_reference_delete($order, 'commerce_line_items', 'line_item_id', $line_item_id);

  // Wrap the line item to be deleted and extract the product from it.
  $wrapper = entity_metadata_wrapper('commerce_line_item', $line_item);
  $product = $wrapper->commerce_product
    ->value();

  // Invoke the product removal event with the line item about to be deleted.
  rules_invoke_all('commerce_cart_product_remove', $order, $product, $line_item->quantity, $line_item);

  // Delete the actual line item.
  commerce_line_item_delete($line_item->line_item_id, $skip_save);
  if (!$skip_save) {
    commerce_order_save($order);
  }
  return $order;
}