function uc_product_class_form_submit in Ubercart 6.2
Same name and namespace in other branches
- 5 uc_product/uc_product.module \uc_product_class_form_submit()
- 7.3 uc_product/uc_product.admin.inc \uc_product_class_form_submit()
Form submission handler for uc_product_class_form().
See also
uc_product_class_form_validate()
File
- uc_product/
uc_product.admin.inc, line 615 - Product administration menu items.
Code
function uc_product_class_form_submit($form, &$form_state) {
$is_new = $form['pcid']['#type'] == 'textfield';
$pcid = $form_state['values']['pcid'];
if ($is_new) {
// Convert whitespace to underscores, and remove other non-alphanumeric characters.
$pcid = preg_replace(array(
'/\\s+/',
'/\\W/',
), array(
'_',
'',
), strtolower($pcid));
db_query("INSERT INTO {uc_product_classes} (pcid, name, description) VALUES ('%s', '%s', '%s')", $pcid, $form_state['values']['name'], $form_state['values']['description']);
uc_product_node_info(TRUE);
variable_set('node_options_' . $pcid, variable_get('node_options_product', array(
'status',
'promote',
)));
if (module_exists('comment')) {
variable_set('comment_' . $pcid, variable_get('comment_product', COMMENT_NODE_READ_WRITE));
}
module_invoke_all('product_class', $pcid, 'insert');
}
else {
db_query("UPDATE {uc_product_classes} SET name = '%s', description = '%s' WHERE pcid = '%s'", $form_state['values']['name'], $form_state['values']['description'], $pcid);
db_query("UPDATE {node_type} SET name = '%s', description = '%s' WHERE type = '%s'", $form_state['values']['name'], $form_state['values']['description'], $pcid);
uc_product_node_info(TRUE);
module_invoke_all('product_class', $pcid, 'update');
}
node_types_rebuild();
if ($is_new && module_exists('imagefield')) {
uc_product_add_default_image_field($pcid);
}
menu_rebuild();
drupal_set_message(t('Product class saved.'));
}