You are here

function commerce_gc_product_line_item_add_form_submit in Commerce GC 7

1 string reference to 'commerce_gc_product_line_item_add_form_submit'
commerce_gc_product_commerce_line_item_type_info_alter in modules/commerce_gc_product/commerce_gc_product.module

File

modules/commerce_gc_product/commerce_gc_product.module, line 153
Provides Giftcard product type and support.

Code

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

  // Make sure the SKU is valid
  $product = commerce_gc_product_load_giftcard_by_sku($element['actions']['sku']['#value']);
  if (!$product) {
    return t('Please enter a valid giftcard product.');
  }
  $lang = LANGUAGE_NONE;
  $line_item_field_elements = $form['commerce_line_items'][$lang]['actions']['line_item_fields'];
  field_attach_form_validate('commerce_line_item', $form_state['line_item'], $line_item_field_elements, $form_state);
  if (form_get_errors()) {
    return;
  }

  // Attach submitted field values.
  field_attach_submit('commerce_line_item', $line_item, $line_item_field_elements, $form_state);

  // Populate the line item just like a regular product.
  commerce_product_line_item_populate($line_item, $product);
}