You are here

function uc_catalog_get_page in Ubercart 5

Same name and namespace in other branches
  1. 6.2 uc_catalog/uc_catalog.module \uc_catalog_get_page()

Load catalog information for display.

Retrieve image, product, and subcategory information for the current term id.

Parameters

$tid: Taxonomy term id.

Return value

A catalog object containing all the information needed to display a catalog page.

1 call to uc_catalog_get_page()
theme_uc_catalog_browse in uc_catalog/uc_catalog.module
Display a formatted catalog page.

File

uc_catalog/uc_catalog.module, line 739
Übercart Catalog module.

Code

function uc_catalog_get_page($tid) {
  $catalog = new stdClass();
  $vid = variable_get('uc_catalog_vid', 0);
  if ($tid) {
    $term = taxonomy_get_term($tid);
    $name = $term->name;
    $description = $term->description;
  }
  else {
    $tid = 0;
    $name = variable_get('uc_catalog_name', t('Catalog'));
    $description = variable_get('uc_catalog_description', '');
  }
  $catalog->tid = $tid;
  $catalog->vid = $vid;
  $catalog->name = $name;
  $catalog->description = $description;
  $catalog->children = array();
  if ($file = uc_catalog_image_load($catalog->tid)) {
    if (module_exists('imagecache')) {
      $file_path = file_create_url(file_directory_path() . '/imagecache/uc_category/' . $file->filepath);
    }
    else {
      $file_path = $file->filepath;
    }
    $info = image_get_info($file_path);
    $catalog->image = $info;
    $catalog->image['filepath'] = $file->filepath;
  }
  $types = module_invoke_all('product_types');
  $links = array();
  $child_list = array();
  $children = taxonomy_get_children($tid, $vid);
  foreach ($children as $child) {
    $n = 0;
    foreach ($types as $type) {
      $n += taxonomy_term_count_nodes($child->tid, $type);
    }
    $child->nodes = $n;

    // Display child category's image.
    if (module_exists('imagecache') && ($file = uc_catalog_image_load($child->tid))) {
      $imagecache_path = file_create_url(file_directory_path() . '/imagecache/uc_category/' . $file->filepath);
      $info = image_get_info($imagecache_path);
      $child->image = $info;
      $child->image['filepath'] = $file->filepath;
    }

    // Display list of child category's children categories.
    // If more than $max_gc_display, show "More..." link to child.
    $grandchildren_list = taxonomy_get_children($child->tid, $vid);
    $child->children = $grandchildren_list;
    $catalog->children[] = $child;
  }

  //$node_resource = taxonomy_select_nodes(array($tid));
  return $catalog;
}