You are here

function commerce_product_pre_calculation_settings_form_submit in Commerce Core 7

Submit callback: process the product sell price pre-calculation form.

File

modules/product_pricing/includes/commerce_product_pricing_ui.admin.inc, line 177
Administrative page callbacks for the Product Pricing UI module.

Code

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

  // Save variables on the form regardless of the button pressed.
  variable_set('commerce_product_sell_price_pre_calculation', $values['commerce_product_sell_price_pre_calculation']);
  if (!empty($values['commerce_product_sell_price_pre_calculation_rules_bypass'])) {
    variable_set('commerce_product_sell_price_pre_calculation_rules_bypass', $values['commerce_product_sell_price_pre_calculation_rules_bypass']);
  }
  if (!empty($values['commerce_product_pricing_callback'])) {
    if ($values['commerce_product_sell_price_pre_calculation'] == 'disabled') {
      variable_set('commerce_product_pricing_callback', $values['commerce_product_pricing_callback']);
    }
    else {

      // If the pre calculation is enabled, revert the Product pricing process
      // to default.
      variable_del('commerce_product_pricing_callback');
    }
  }

  // React to the management buttons if they were used to submit the form.
  // If the batch calculation button was pressed, setup the batch now.
  if (!empty($values['batch_calculate']) && $values['op'] == $values['batch_calculate']) {
    commerce_product_batch_pre_calculate_sell_prices();
  }

  // TODO: Expand the API to allow for deletion of pre-calculated prices and
  // get this query the heck out of here.
  if (!empty($values['delete']) && $values['op'] == $values['delete']) {
    db_delete('commerce_calculated_price')
      ->condition('module', 'commerce_product_pricing')
      ->condition('entity_type', 'commerce_product')
      ->condition('field_name', 'commerce_price')
      ->execute();
  }
}