You are here

function commerce_shipping_line_item_add_form_submit in Commerce Shipping 7

Same name and namespace in other branches
  1. 7.2 commerce_shipping.module \commerce_shipping_line_item_add_form_submit()

Adds the selected shipping information to a line item added via a line item manager widget.

Parameters

$line_item: The newly created line item object.

$element: The array representing the widget form element.

$form_state: The present state of the form upon the latest submission.

$form: The actual form array.

Return value

NULL if all is well or an error message if something goes wrong.

File

./commerce_shipping.module, line 234
Defines the shipping system and checkout integration.

Code

function commerce_shipping_line_item_add_form_submit(&$line_item, $element, &$form_state, $form) {
  $order = $form_state['commerce_order'];

  // Populate the line item with the shipping data.
  $line_item_wrapper = entity_metadata_wrapper('commerce_line_item', $line_item);
  $line_item_wrapper->commerce_shipping_method = $element['actions']['shipping_method']['#value'];
  $line_item_wrapper->commerce_unit_price->amount = commerce_currency_decimal_to_amount($element['actions']['amount']['#value'], $element['actions']['currency_code']['#value']);
  $line_item_wrapper->commerce_unit_price->currency_code = $element['actions']['currency_code']['#value'];
  $line_item_wrapper->commerce_unit_price->data = commerce_price_component_add($line_item_wrapper->commerce_unit_price
    ->value(), 'quote', $line_item_wrapper->commerce_unit_price
    ->value(), TRUE, FALSE);
}