1
Answers
Vote up!
0
Vote down!

How to use custom line item types in checkout

My objective is to:
a) Create a custom line item type
b) Create an order programatically with a custom line item
c) Redirect to checkout page

I can do a) and b) but c) does not work:

I can create a custom line item type using the commerce_example line_item_example module.

I can create a new order and include a custom line item as follow:

$order = commerce_order_new($user->uid, 'checkout_checkout')
commerce_order_save($order);

// Add the custom line item
$line_item = line_item_example_line_item_2_new($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);

But when I redirect to the checkout page with drupal_goto('checkout/' . $order->order_id); it breaks.

After looking at the checkout callback in commerce_checkout.module called commerce_checkout_router(), I found code that redirects away if the line item is not of type "product". Also the cart summary view filters out any line item that is not of type "product".

So how does one use the commerce checkout page for custom line items?

Asked by: odiennef
on October 15, 2012

1 Answer