You are here

function uc_attribute_nodeapi in Ubercart 6.2

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

Implements hook_nodeapi().

File

uc_attribute/uc_attribute.module, line 367

Code

function uc_attribute_nodeapi(&$node, $op, $arg3 = NULL, $arg4 = NULL) {
  if (uc_product_is_product($node->type)) {
    switch ($op) {
      case 'load':
        $attributes = uc_product_get_attributes($node->nid);
        if (is_array($attributes) && !empty($attributes)) {
          $node->attributes = $attributes;
          return array(
            'attributes' => $attributes,
          );
        }
        break;
      case 'insert':
        uc_attribute_node_insert($node);
        break;
      case 'delete':
        uc_attribute_node_delete($node);
        break;
      case 'update index':
        $output = '';
        $attributes = uc_product_get_attributes($node->nid);
        foreach ($attributes as $attribute) {
          $output .= '<h3>' . _uc_attribute_get_name($attribute) . '</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;
    }
  }
}