Showing posts with label commerce order programmatically. Show all posts
Showing posts with label commerce order programmatically. Show all posts

Friday, January 30, 2015

Create an commerce order programmatically

The following steps to describe about to create an commerce order programmatically in Drupal

global $user;
$product_id = 100;
$quantity = 1;

$order = commerce_order_new($user->uid, 'cart');
commerce_order_save($order);
$line_item = commerce_product_line_item_new($product, $quantity, $order->order_id);
commerce_line_item_save($line_item);
$order_wrapper = entity_metadata_wrapper('commerce_order', $order);
$order_wrapper->commerce_line_items[] = $line_item;
commerce_order_save($order);