You are here

function uc_order_delete in Ubercart 7.3

Same name and namespace in other branches
  1. 5 uc_order/uc_order.module \uc_order_delete()
  2. 6.2 uc_order/uc_order.module \uc_order_delete()

Entity API "deletion callback" for uc_order entity.

Deletes an order and tells other modules to do the same.

Parameters

$order_id: The ID of the order you wish to delete.

4 calls to uc_order_delete()
UbercartOrderTestCase::testEntityHooks in uc_order/tests/uc_order.test
Tests order entity CRUD hooks.
UbercartOrderTestCase::testOrderApi in uc_order/tests/uc_order.test
Tests order entity API functions.
uc_order_action_delete in uc_order/uc_order.module
Action implementation: delete an order.
uc_order_delete_confirm_form_submit in uc_order/uc_order.admin.inc
Form submission handler for uc_order_delete_confirm_form().
1 string reference to 'uc_order_delete'
uc_order_entity_info in uc_order/uc_order.module
Implements hook_entity_info().

File

uc_order/uc_order.module, line 1025

Code

function uc_order_delete($order_id) {
  global $user;
  $order = uc_order_load($order_id);

  // Perform the operations if we're deleting a valid order.
  if ($order !== FALSE) {
    rules_invoke_event('uc_order_delete', $order);
    uc_order_module_invoke('delete', $order, NULL);
    module_invoke_all('entity_delete', $order, 'uc_order');

    // Delete data from the appropriate Ubercart order tables.
    db_delete('uc_orders')
      ->condition('order_id', $order_id)
      ->execute();
    $efq = new EntityFieldQuery();
    $result = $efq
      ->entityCondition('entity_type', 'uc_order_product')
      ->propertyCondition('order_id', $order->order_id)
      ->execute();
    if (!empty($result['uc_order_product'])) {
      $product_ids = array_keys($result['uc_order_product']);
      uc_order_product_delete_multiple($product_ids);
    }
    db_delete('uc_order_comments')
      ->condition('order_id', $order_id)
      ->execute();
    db_delete('uc_order_admin_comments')
      ->condition('order_id', $order_id)
      ->execute();
    db_delete('uc_order_log')
      ->condition('order_id', $order_id)
      ->execute();

    // Delete line items for the order.
    uc_order_delete_line_item($order_id, TRUE);

    // Delete attached field values.
    field_attach_delete('uc_order', $order);

    // Log the action in the database.
    watchdog('uc_order', 'Order @order_id deleted by user @uid.', array(
      '@order_id' => $order_id,
      '@uid' => $user->uid,
    ));
  }
}