You are here

function commerce_cart_order_new in Commerce Core 7

Creates a new shopping cart order for the specified user.

Parameters

$uid: The uid of the user for whom to create the order. If left 0, the order will be created for an anonymous user and associated with the current session if it is anonymous.

$type: The type of the order; defaults to the standard 'commerce_order' type.

Return value

The newly created shopping cart order object.

1 call to commerce_cart_order_new()
commerce_cart_product_add in modules/cart/commerce_cart.module
Adds the specified product to a customer's shopping cart.

File

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

Code

function commerce_cart_order_new($uid = 0, $type = 'commerce_order') {
  global $user;

  // Create the new order with the customer's uid and the cart order status.
  $order = commerce_order_new($uid, 'cart', $type);
  $order->log = t('Created as a shopping cart order.');

  // Save it so it gets an order ID and return the full object.
  commerce_order_save($order);

  // Reset the cart cache
  commerce_cart_order_ids_reset();

  // If the user is not logged in, ensure the order ID is stored in the session.
  if (!$uid && empty($user->uid)) {
    commerce_cart_order_session_save($order->order_id);
  }
  return $order;
}