You are here

function uc_attribute_nodeapi in Ubercart 5

Same name and namespace in other branches
  1. 6.2 uc_attribute/uc_attribute.module \uc_attribute_nodeapi()

Implementation of hook_nodeapi().

File

uc_attribute/uc_attribute.module, line 267

Code

function uc_attribute_nodeapi(&$node, $op, $arg3 = null, $arg4 = null) {
  if (in_array($node->type, module_invoke_all('product_types'))) {
    switch ($op) {
      case 'insert':
        switch ($GLOBALS['db_type']) {
          case 'mysqli':
          case 'mysql':
            db_query("INSERT IGNORE INTO {uc_product_attributes} (nid, aid, ordering, required, display, default_option) SELECT %d, aid, ordering, required, display, default_option FROM {uc_class_attributes} WHERE pcid = '%s'", $node->nid, $node->type);
            db_query("INSERT IGNORE INTO {uc_product_options} (nid, oid, cost, price, weight, ordering) SELECT %d, oid, cost, price, weight, ordering FROM {uc_class_attribute_options} WHERE pcid = '%s'", $node->nid, $node->type);
            break;
          case 'pgsql':
            db_query("INSERT INTO {uc_product_attributes} (nid, aid, ordering, required, display, default_option) SELECT %d, aid, ordering, required, display, default_option FROM {uc_class_attributes} WHERE pcid = '%s'", $node->nid, $node->type);
            db_query("INSERT INTO {uc_product_options} (nid, oid, cost, price, weight, ordering) SELECT %d, oid, cost, price, weight, ordering FROM {uc_class_attribute_options} WHERE pcid = '%s'", $node->nid, $node->type);
            break;
        }
        break;
      case 'delete':
        db_query("DELETE FROM {uc_product_options} WHERE nid = %d", $node->nid);
        db_query("DELETE FROM {uc_product_adjustments} WHERE nid = %d", $node->nid);
        db_query("DELETE FROM {uc_product_attributes} WHERE nid = %d", $node->nid);
        break;
      case 'update index':
        $output = '';
        $attributes = uc_product_get_attributes($node->nid);
        foreach ($attributes as $attribute) {
          $output .= '<h3>' . $attribute->name . '</h3>';
          foreach ($attribute->options as $option) {
            $output .= $option->name . ' ';
          }
          $output .= "\n";
        }
        $result = db_query("SELECT model FROM {uc_product_adjustments} WHERE nid = %d", $node->nid);
        while ($adjustment = db_fetch_object($result)) {
          $output .= '<h2>' . $adjustment->model . "<h2>\n";
        }
        return $output;
    }
  }
}