You are here

function commerce_vat_price_field_validate in Commerce VAT 7

Validate callback for the vat inclusion select list that serves to reset the data array based on the selected vat.

1 string reference to 'commerce_vat_price_field_validate'
commerce_vat_field_widget_form_alter in ./commerce_vat.module
Implements hook_field_widget_form_alter().

File

./commerce_vat.module, line 484
Defines VAT rates and Rules integration for configuring vat rules for applicability and display.

Code

function commerce_vat_price_field_validate($element, &$form_state) {
  $direction = variable_get('commerce_vat_direction', 'forward');
  if ($direction == 'forward') {

    // Build an array of form parents to the price array.
    $parents = $element['#parents'];

    // Get the price array from the form state.
    $price = $form_state['values'];
    foreach ($parents as $parent) {
      $price = $price[$parent];
    }
    $price['data']['rounded_up'] = $element['rounded_up']['#value'];

    // Add the data array to the form state.
    $parents[] = 'data';
    form_set_value(array(
      '#parents' => $parents,
    ), $price['data'], $form_state);
  }
}