function uc_varprice_nodeapi in UC Variable Price 6
Implementation of hook_nodeapi().
Summary of alterations: 1) Removes price displays from variable priced product nodes. 2) Inserts Variable Price product feature on product node creation.
File
- ./
uc_varprice.module, line 221 - Defines a product feature to turn any product into a variable priced product.
Code
function uc_varprice_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
// When the node is being prepped for display...
if ($op === 'view') {
// If this node has a variable price product feature...
if (db_result(db_query("SELECT pfid FROM {uc_product_features} WHERE fid = 'varprice' AND nid = %d", $node->nid))) {
// Hide all the prices from display.
$node->content['cost']['#access'] = FALSE;
$node->content['list_price']['#access'] = FALSE;
$node->content['sell_price']['#access'] = FALSE;
$node->content['display_price']['#access'] = FALSE;
}
}
elseif (uc_product_is_product($node)) {
// When a product node is created...
if ($op === 'insert') {
$data = variable_get('ucvp_class_def_' . $node->type, array());
// If the product class has a default Variable Price product feature...
if ($data) {
// Prepare the data as if it were from a form submission.
$data = unserialize($data);
$data['nid'] = $node->nid;
$data['pfid'] = '';
$form_state = array(
'values' => $data,
);
// Add the feature to the product by spoofing the normal form submission.
$form_state['values']['sel_options_arr'] = $form_state['values']['sel_options'];
uc_varprice_feature_form_submit(array(), $form_state);
}
}
elseif ($op === 'delete') {
$data = uc_varprice_product_load($node->nid);
if ($data) {
db_query('DELETE FROM {uc_varprice_products} WHERE vpid = %d', $data->vpid);
}
}
}
}