You are here

function uc_usps_nodeapi in Ubercart 5

Same name and namespace in other branches
  1. 6.2 shipping/uc_usps/uc_usps.module \uc_usps_nodeapi()

Implementation of hook_nodeapi().

File

shipping/uc_usps/uc_usps.module, line 64
Shipping quote method module that receives quotes from the United States Postal Service via XML web service.

Code

function uc_usps_nodeapi(&$node, $op) {
  if (in_array($node->type, module_invoke_all('product_types'))) {
    switch ($op) {
      case 'insert':
      case 'update':
        if (isset($node->usps)) {
          $usps_values = $node->usps;
          if (!$node->revision) {
            db_query("DELETE FROM {uc_usps_products} WHERE vid = %d", $node->vid);
          }
          db_query("INSERT INTO {uc_usps_products} (vid, nid, container) VALUES (%d, %d, '%s')", $node->vid, $node->nid, $usps_values['container']);
        }
        break;
      case 'load':
        if (uc_product_get_shipping_type($node) == 'small_package') {
          return array(
            'usps' => db_fetch_array(db_query("SELECT * FROM {uc_usps_products} WHERE vid = %d", $node->vid)),
          );
        }
        break;
      case 'delete':
        db_query("DELETE FROM {uc_usps_products} WHERE nid = %d", $node->nid);
        break;
      case 'delete revision':
        db_query("DELETE FROM {uc_usps_products} WHERE vid = %d", $node->vid);
        break;
    }
  }
}