You are here

function commerce_pricelist_item_form_submit in Commerce Pricelist 7

Form submit handler: Submits basic_add_form information.

File

includes/commerce_pricelist.admin.inc, line 748
Summary

Code

function commerce_pricelist_item_form_submit($form, &$form_state) {
  $entity = $form_state['values']['entity'];

  // Convert to timestamp.
  foreach (array(
    'valid_from',
    'valid_to',
  ) as $date_field) {
    $timestamp = strtotime($form_state['values'][$date_field]);
    $form_state['values'][$date_field] = $timestamp !== FALSE ? $timestamp : '';
  }

  // Need to shuffle values around because we wrap them and use
  // commerce_price_field_widget_validate().
  $price = $form_state['values']['price'];
  unset($form_state['values']['price']);
  $form_state['values']['price_amount'] = $price['amount'];
  $form_state['values']['currency_code'] = $price['currency_code'];
  foreach ($form_state['values'] as $key => $value) {
    $entity->{$key} = $value;
  }
  field_attach_submit('commerce_pricelist_item', $entity, $form, $form_state);
  $entity = commerce_pricelist_item_save($entity);
  if ($entity) {
    drupal_set_message(t('Price list item saved'));
  }
}