You are here

function uc_catalog_nodeapi in Ubercart 6.2

Same name and namespace in other branches
  1. 5 uc_catalog/uc_catalog.module \uc_catalog_nodeapi()

Implements hook_nodeapi().

File

uc_catalog/uc_catalog.module, line 215
Ubercart Catalog module.

Code

function uc_catalog_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
  static $parents = array();
  if (uc_product_is_product($node->type)) {
    switch ($op) {
      case 'view':
        if ($a4 == TRUE && variable_get('uc_catalog_breadcrumb', TRUE)) {
          $crumbs = array();
          if (!_uc_catalog_is_frontpage()) {
            $crumbs[] = l(t('Home'), '');
          }
          $terms = taxonomy_node_get_terms_by_vocabulary($node, variable_get('uc_catalog_vid', 0));
          if (count($terms)) {
            $crumbs[] = l(variable_get('uc_catalog_name', t('Catalog')), 'catalog');
            $used_tids = array();
            foreach ($terms as $term) {
              if (!isset($parents[$term->tid])) {
                $parents[$term->tid] = taxonomy_get_parents_all($term->tid);
              }

              //drupal_set_message('<pre>'. print_r($parents[$term->tid], TRUE) .'</pre>');
              foreach (array_reverse($parents[$term->tid]) as $parent) {
                if (!in_array($parent->tid, $used_tids)) {
                  $crumbs[] = l($parent->name, uc_catalog_path($parent));
                  $used_tids[] = $parent->tid;
                }
              }
            }
          }
          drupal_set_breadcrumb($crumbs);
        }
        break;
    }
  }
}