commerce_cart_order_new
| DC commerce_cart.module | commerce_cart_order_new($uid = 0) |
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 the current user and associated with his or her session.
Return value
The newly created shopping cart order object.
File
- sites/
all/ modules/ commerce/ modules/ cart/ commerce_cart.module, line 643 - Implements the shopping cart system and add to cart features.
Code
<?php
function commerce_cart_order_new($uid = 0) {
// Create the new order with the customer's uid and the cart order status.
$order = commerce_order_new($uid, 'cart');
$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) {
commerce_cart_order_session_save($order->order_id);
}
return $order;
}
?> 