function uc_flatrate_nodeapi in Ubercart 5
Same name and namespace in other branches
- 6.2 shipping/uc_flatrate/uc_flatrate.module \uc_flatrate_nodeapi()
Implementation of hook_nodeapi().
File
- shipping/
uc_flatrate/ uc_flatrate.module, line 89 - Shipping quote module that defines a flat shipping rate for each product.
Code
function uc_flatrate_nodeapi(&$node, $op) {
if (in_array($node->type, module_invoke_all('product_types'))) {
switch ($op) {
case 'insert':
case 'update':
if (is_array($node->flatrate)) {
if (!$node->revision) {
db_query("DELETE FROM {uc_flatrate_products} WHERE vid = %d", $node->vid);
}
foreach ($node->flatrate as $mid => $rate) {
if ($rate !== '') {
db_query("INSERT INTO {uc_flatrate_products} (vid, nid, mid, rate) VALUES (%d, %d, %d, %f)", $node->vid, $node->nid, $mid, $rate);
}
}
}
break;
case 'load':
$return = array(
'flatrate' => array(),
);
$result = db_query("SELECT mid, rate FROM {uc_flatrate_products} WHERE vid = %d", $node->vid);
while ($rate = db_fetch_object($result)) {
$return['flatrate'][$rate->mid] = $rate->rate;
}
$result = db_query("SELECT mid, product_rate FROM {uc_flatrate_methods}");
while ($method = db_fetch_object($result)) {
$rate = $return['flatrate'][$method->mid];
if ($rate === null || $rate < 0) {
$return['flatrate'][$method->mid] = $method->product_rate;
}
}
return $return;
break;
case 'delete':
db_query("DELETE FROM {uc_flatrate_products} WHERE nid = %d", $node->nid);
break;
case 'delete revision':
db_query("DELETE FROM {uc_flatrate_products} WHERE vid = %d", $node->vid);
break;
}
}
}