function uc_attribute_option_form_submit in Ubercart 6.2
Same name and namespace in other branches
- 5 uc_attribute/uc_attribute.module \uc_attribute_option_form_submit()
- 7.3 uc_attribute/uc_attribute.admin.inc \uc_attribute_option_form_submit()
Form submission handler for uc_attribute_option_form().
See also
uc_attribute_option_form_validate()
File
- uc_attribute/
uc_attribute.admin.inc, line 581 - Attribute administration menu items.
Code
function uc_attribute_option_form_submit($form, &$form_state) {
if (!isset($form_state['values']['oid'])) {
db_query("INSERT INTO {uc_attribute_options} (aid, name, cost, price, weight, ordering) VALUES (%d, '%s', %f, %f, %f, %d)", $form_state['values']['aid'], $form_state['values']['name'], $form_state['values']['cost'], $form_state['values']['price'], $form_state['values']['weight'], $form_state['values']['ordering']);
$form_state['values']['oid'] = db_last_insert_id('uc_attribute_options', 'oid');
drupal_set_message(t('Created new option %option.', array(
'%option' => $form_state['values']['name'],
)));
watchdog('uc_attribute', 'Created new option %option.', array(
'%option' => $form_state['values']['name'],
), WATCHDOG_NOTICE, 'admin/store/attributes/' . $form_state['values']['aid'] . '/options/add');
$form_state['redirect'] = 'admin/store/attributes/' . $form_state['values']['aid'] . '/options/add';
}
else {
db_query("UPDATE {uc_attribute_options} SET name = '%s', cost = %f, price = %f, weight = %f, ordering = %d WHERE aid = %d AND oid = %d", $form_state['values']['name'], $form_state['values']['cost'], $form_state['values']['price'], $form_state['values']['weight'], $form_state['values']['ordering'], $form_state['values']['aid'], $form_state['values']['oid']);
drupal_set_message(t('Updated option %option.', array(
'%option' => $form_state['values']['name'],
)));
if ($form_state['values']['bulk_update']) {
db_query("UPDATE {uc_product_options} SET cost = '%f', price = '%f', weight = '%f', ordering = '%d' WHERE oid = '%d'", $form_state['values']['cost'], $form_state['values']['price'], $form_state['values']['weight'], $form_state['values']['ordering'], $form_state['values']['oid']);
db_query("UPDATE {uc_class_attribute_options} SET cost = '%f', price = '%f', weight = '%f', ordering = '%d' WHERE oid = '%d'", $form_state['values']['cost'], $form_state['values']['price'], $form_state['values']['weight'], $form_state['values']['ordering'], $form_state['values']['oid']);
drupal_set_message(t('Bulk updates applied to all products and classes which have this attribute.'));
watchdog('uc_attribute', 'Updated option %option for all products and classes.', array(
'%option' => $form_state['values']['name'],
), WATCHDOG_NOTICE, 'admin/store/attributes/' . $form_state['values']['aid'] . '/options/' . $form_state['values']['oid']);
}
else {
watchdog('uc_attribute', 'Updated option %option.', array(
'%option' => $form_state['values']['name'],
), WATCHDOG_NOTICE, 'admin/store/attributes/' . $form_state['values']['aid'] . '/options/' . $form_state['values']['oid']);
}
$form_state['redirect'] = 'admin/store/attributes/' . $form_state['values']['aid'] . '/options';
}
}