You are here

function commerce_product_line_item_add_form_submit in Commerce Core 7

Adds the selected product 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

modules/product_reference/commerce_product_reference.module, line 1357
Defines a field type for referencing products from other entities.

Code

function commerce_product_line_item_add_form_submit(&$line_item, $element, &$form_state, $form) {

  // Load the selected product.
  if ($product = commerce_product_load_by_sku($element['actions']['product_sku']['#value'])) {

    // Populate the line item with the product data.
    commerce_product_line_item_populate($line_item, $product);
  }
  else {
    return t('You have entered an invalid product SKU.');
  }
}