function uc_varprice_feature_form_submit in UC Variable Price 6
Same name and namespace in other branches
- 7 uc_varprice.module \uc_varprice_feature_form_submit()
1 call to uc_varprice_feature_form_submit()
- uc_varprice_nodeapi in ./uc_varprice.module
- Implementation of hook_nodeapi().
File
- ./uc_varprice.module, line 494
- Defines a product feature to turn any product into a variable priced product.
Code
function uc_varprice_feature_form_submit($form, &$form_state) {
$vp_data = array(
'pfid' => $form_state['values']['pfid'],
'price_default' => $form_state['values']['price_default'],
'price_minimum' => $form_state['values']['price_minimum'],
'price_maximum' => $form_state['values']['price_maximum'],
'add_to_cart_title' => $form_state['values']['override_add_to_cart_title'] ? $form_state['values']['add_to_cart_title'] : '',
'amount_title' => $form_state['values']['override_amount_title'] ? $form_state['values']['amount_title'] : '',
'arbitrary' => intval($form_state['values']['arbitrary']),
'selectable' => intval($form_state['values']['selectable']),
'sel_widget' => $form_state['values']['sel_widget'],
'sel_options' => serialize($form_state['values']['sel_options_arr']),
);
$description = array(
t('Customers can specify a price for this product.'),
t('<strong>Default price:</strong> @price', array(
'@price' => uc_currency_format($vp_data['price_default']),
)),
);
if (!empty($vp_data['amount_title'])) {
$description[] = t('<strong>Amount field title:</strong> @title', array(
'@title' => $vp_data['amount_title'],
));
}
if ($vp_data['selectable']) {
$description[] = t('Customers may select a price from a list.');
$description[] = t('<strong>Selectable prices:</strong> @prices', array(
'@prices' => implode(', ', $form_state['values']['sel_options_arr']),
));
if ($form_state['values']['sel_widget'] === 'radios') {
$description[] = t('Prices are selected with <strong>radio buttons</strong>.');
}
elseif ($form_state['values']['sel_widget'] === 'select') {
$description[] = t('Prices are selected with a <strong>drop-down menu</strong>.');
}
}
if ($vp_data['arbitrary']) {
$description[] = t('Customers may enter an arbitrary price.');
if (!empty($vp_data['price_minimum'])) {
$description[] = t('<strong>Minimum price:</strong> @price', array(
'@price' => uc_currency_format($vp_data['price_minimum']),
));
}
if (!empty($vp_data['price_maximum'])) {
$description[] = t('<strong>Maximum price:</strong> @price', array(
'@price' => uc_currency_format($vp_data['price_maximum']),
));
}
if (!empty($vp_data['add_to_cart_title'])) {
$description[] = t('<strong>Add to cart title:</strong> @title', array(
'@title' => $vp_data['add_to_cart_title'],
));
}
}
$data = array(
'pfid' => $vp_data['pfid'],
'nid' => $form_state['values']['nid'],
'fid' => 'varprice',
'description' => implode('<br />', $description),
);
$form_state['redirect'] = uc_product_feature_save($data);
if (empty($data['pfid'])) {
$vp_data['pfid'] = db_last_insert_id('uc_product_features', 'pfid');
$key = NULL;
}
else {
$vp_data['vpid'] = db_result(db_query("SELECT vpid FROM {uc_varprice_products} WHERE pfid = %d", $data['pfid']));
$key = 'vpid';
}
drupal_write_record('uc_varprice_products', $vp_data, $key);
}