function uc_weightquote_nodeapi in Ubercart 6.2
Same name and namespace in other branches
- 5 shipping/uc_weightquote/uc_weightquote.module \uc_weightquote_nodeapi()
Implements hook_nodeapi().
File
- shipping/
uc_weightquote/ uc_weightquote.module, line 92 - Shipping quote module that defines a weight-based shipping rate for each product.
Code
function uc_weightquote_nodeapi(&$node, $op) {
if (uc_product_is_product($node->type)) {
switch ($op) {
case 'insert':
case 'update':
if (isset($node->weightquote) && is_array($node->weightquote)) {
if (!$node->revision) {
db_query("DELETE FROM {uc_weightquote_products} WHERE vid = %d", $node->vid);
}
foreach ($node->weightquote as $mid => $rate) {
if (is_numeric($rate) && $rate >= 0) {
db_query("INSERT INTO {uc_weightquote_products} (vid, nid, mid, rate) VALUES (%d, %d, %d, %f)", $node->vid, $node->nid, $mid, $rate);
}
}
}
break;
case 'load':
$return = array(
'weightquote' => array(),
);
$result = db_query("SELECT mid, rate FROM {uc_weightquote_products} WHERE vid = %d", $node->vid);
while ($rate = db_fetch_object($result)) {
$return['weightquote'][$rate->mid] = $rate->rate;
}
return $return;
break;
case 'delete':
db_query("DELETE FROM {uc_weightquote_products} WHERE nid = %d", $node->nid);
break;
case 'delete revision':
db_query("DELETE FROM {uc_weightquote_products} WHERE vid = %d", $node->vid);
break;
}
}
}