You are here

function uc_order_save in Ubercart 7.3

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

Entity API "save callback" for uc_order entity.

Saves an order to the database.

13 calls to uc_order_save()
UbercartCartCheckoutTestCase::createOrder in uc_cart/tests/uc_cart.test
Creates a new order.
UbercartCreditCardTestCase::createOrder in payment/uc_credit/tests/uc_credit.test
Helper function. Creates a new order.
UbercartOrderTestCase::testEntityHooks in uc_order/tests/uc_order.test
Tests order entity CRUD hooks.
UbercartOrderTestCase::ucCreateOrder in uc_order/tests/uc_order.test
Helper function for creating an order programmatically.
uc_2checkout_complete in payment/uc_2checkout/uc_2checkout.pages.inc
Finalizes 2Checkout transaction.

... See full list

1 string reference to 'uc_order_save'
uc_order_entity_info in uc_order/uc_order.module
Implements hook_entity_info().

File

uc_order/uc_order.module, line 971

Code

function uc_order_save($order) {
  $transaction = db_transaction();
  try {
    if (is_null($order->order_id) || intval($order->order_id) == 0) {
      return FALSE;
    }
    field_attach_presave('uc_order', $order);
    $order->order_total = uc_order_get_total($order);
    $order->product_count = uc_order_get_product_count($order);
    if (is_null($order->delivery_country) || $order->delivery_country == 0) {
      $order->delivery_country = variable_get('uc_store_country', 840);
    }
    if (is_null($order->billing_country) || $order->billing_country == 0) {
      $order->billing_country = variable_get('uc_store_country', 840);
    }
    $order->host = ip_address();
    $order->modified = REQUEST_TIME;
    uc_order_module_invoke('presave', $order, NULL);
    module_invoke_all('entity_presave', $order, 'uc_order');
    drupal_write_record('uc_orders', $order, 'order_id');
    if (is_array($order->products)) {
      foreach ($order->products as $product) {
        drupal_alter('uc_order_product', $product, $order);
        uc_order_product_save($order->order_id, $product);
      }
    }
    field_attach_update('uc_order', $order);
    uc_order_module_invoke('save', $order, NULL);
    module_invoke_all('entity_update', $order, 'uc_order');
    $order->order_total = uc_order_get_total($order);
  } catch (Exception $e) {
    $transaction
      ->rollback('uc_order');
    watchdog_exception('uc_order', $e);
    throw $e;
  }
}