You are here

function uc_product_class_load in Ubercart 6.2

Same name and namespace in other branches
  1. 5 uc_product/uc_product.module \uc_product_class_load()
  2. 7.3 uc_product/uc_product.module \uc_product_class_load()

Loads a product class, or all classes.

2 calls to uc_product_class_load()
uc_product_class_default in uc_product/uc_product.admin.inc
Displays a list of product classes.
uc_product_node_info in uc_product/uc_product.module
Implements hook_node_info().

File

uc_product/uc_product.module, line 1854
The product module for Ubercart.

Code

function uc_product_class_load($class_id = NULL, $reset = FALSE) {
  static $classes;
  if ($reset || !isset($classes)) {

    // Load classes from database.
    $classes = array();
    $result = db_query("SELECT * FROM {uc_product_classes}");
    while ($class = db_fetch_object($result)) {
      $classes[$class->pcid] = $class;
    }

    // Merge any module-defined classes.
    foreach (module_invoke_all('uc_product_default_classes') as $pcid => $class) {

      // The default class can be overridden by a module if needed,
      // but is not treated as a real class elsewhere.
      if ($pcid == 'product') {
        continue;
      }
      $class += array(
        'pcid' => $pcid,
        'name' => $pcid,
        'description' => '',
      );
      if (isset($classes[$pcid])) {

        // Merge defaults with the existing database info.
        $classes[$pcid] = (object) array_merge($class, (array) $classes[$pcid]);
      }
      else {

        // Ensure the class info is saved in the database.
        drupal_write_record('uc_product_classes', $class);
        $classes[$pcid] = (object) $class;
      }

      // Module-defined classes cannot be deleted.
      $classes[$pcid]->locked = TRUE;
    }
  }
  return is_null($class_id) ? $classes : $classes[$class_id];
}