I'm trying to create a gift wrapping module for Drupal commerce. I have created the checkout pane that has a select box for the user to choose if they want their order gift wrapped (and a field to select the giftwrap price on the configuration form). I've also created a giftwrap line item type. In the pane's base_checkout_form_submit() function I would like to create a giftwrap line item that is added to the order alongside the products. This is what I've got so far:
/**
* Implements base_checkout_form_submit()
*/
function commerce_giftwrap_pane_checkout_form_submit($form, &$form_state, $checkout_pane, $order) {
$default_currency_code = commerce_default_currency();
if ($balance = commerce_payment_order_balance($order)) {
$default_currency_code = $balance['currency_code'];
}
// Create the new line item.
$line_item = commerce_line_item_new('giftwrap', $order->order_id);
$line_item->line_item_label = 'Gift Wrapping';
$line_item->quantity = 1;
$line_item->commerce_unit_price['amount'] = variable_get('commerce_giftwrap_price', '2.00');
$line_item->commerce_unit_price['currency_code'] = $default_currency_code;
commerce_line_item_save($line_item);
}
I haven't wrapped it in an if statement yet, I wanted to get it working first. This code is creating a line item in the database however it isn't adding the line item to shopping cart contents view on the checkout review page. I've altered the shopping cart view to include product line items and my newly created giftwrap line items.
Any help on this would be greatly appreciated.