You are here

function uc_object_options_form_submit in Ubercart 5

Same name and namespace in other branches
  1. 6.2 uc_attribute/uc_attribute.admin.inc \uc_object_options_form_submit()
  2. 7.3 uc_attribute/uc_attribute.admin.inc \uc_object_options_form_submit()

File

uc_attribute/uc_attribute.module, line 1130

Code

function uc_object_options_form_submit($form_id, $form_values) {
  if ($form_values['type'] == 'product') {
    $attr_table = '{uc_product_attributes}';
    $opt_table = '{uc_product_options}';
    $id = 'nid';
    $sql_type = '%d';
  }
  else {
    if ($form_values['type'] == 'class') {
      $attr_table = '{uc_class_attributes}';
      $opt_table = '{uc_class_attribute_options}';
      $id = 'pcid';
      $sql_type = "'%s'";
    }
  }
  foreach ($form_values['attributes'] as $attribute) {
    db_query("UPDATE {$attr_table} SET default_option = %d WHERE {$id} = {$sql_type} AND aid = %d", $attribute['default'], $form_values['id'], $attribute['aid']);
    if (is_array($attribute['options'])) {
      foreach ($attribute['options'] as $oid => $option) {
        db_query("DELETE FROM {$opt_table} WHERE {$id} = {$sql_type} AND oid = %d", $form_values['id'], $oid);
        if ($option['select']) {
          db_query("INSERT INTO {$opt_table} ({$id}, oid, cost, price, weight, ordering) VALUES ({$sql_type}, %d, %f, %f, %f, %d)", $form_values['id'], $oid, $option['cost'], $option['price'], $option['weight'], $option['ordering']);
        }
        else {
          if ($form_values['type'] == 'product') {
            $aid = $attribute['aid'];
            $match = 'i:' . $aid . ';s:' . strlen($oid) . ':"' . $oid . '";';
            db_query("DELETE FROM {uc_product_adjustments} WHERE nid = %d AND combination LIKE '%%%s%%'", $form_values['id'], $match);
          }
        }
      }
    }
  }
  drupal_set_message(t('The !type options have been saved.', array(
    '!type' => $form_values['type'] == 'product' ? t('product') : t('product class'),
  )));
}