You are here

function uc_catalog_store_status in Ubercart 6.2

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

Implements hook_store_status().

Provides status information about the "Product Catalog" and products not listed in the catalog.

File

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

Code

function uc_catalog_store_status() {
  $statuses = array();
  $cat_id = variable_get('uc_catalog_vid', 0);
  $catalog = taxonomy_vocabulary_load($cat_id);
  if ($catalog) {
    $statuses[] = array(
      'status' => 'ok',
      'title' => t('Catalog vocabulary'),
      'desc' => t('Vocabulary !name has been identified as the Ubercart catalog.', array(
        '!name' => l($catalog->name, 'admin/content/taxonomy/' . $catalog->vid),
      )),
    );
    $excluded = 0;
    $result = db_query("SELECT COUNT(DISTINCT n.nid) FROM {node} AS n LEFT JOIN {term_node} AS tn ON n.nid = tn.nid LEFT JOIN {vocabulary_node_types} AS vnt ON n.type = vnt.type WHERE n.type <> 'image' AND tn.tid IS NULL AND vnt.vid = %d", $cat_id);
    if ($excluded = db_result($result)) {
      $description = format_plural($excluded, 'There is @count product not listed in the catalog.', 'There are @count products not listed in the catalog.') . t(' Products are listed by assigning a category from the <a href="!cat_url">Product Catalog</a> vocabulary to them.', array(
        '!cat_url' => url('admin/content/taxonomy/' . $catalog->vid),
      ));
      $terms = db_result(db_query("SELECT COUNT(*) FROM {term_data} WHERE vid = %d", $catalog->vid));
      if ($terms) {
        $description .= ' ' . l(t('Find orphaned products here.'), 'admin/store/products/orphans');
      }
      else {
        $description .= ' ' . l(t('Add terms for the products to inhabit.'), 'admin/content/taxonomy/' . $catalog->vid . '/add/term');
      }
      $statuses[] = array(
        'status' => 'warning',
        'title' => t('Unlisted products'),
        'desc' => $description,
      );
    }
  }
  else {
    $statuses[] = array(
      'status' => 'error',
      'title' => t('Catalog vocabulary'),
      'desc' => t('No vocabulary has been recognized as the Ubercart catalog. Choose one on <a href="!admin_catalog">this page</a> or add one on the <a href="!admin_vocab">taxonomy admin page</a> first, if needed.', array(
        '!admin_catalog' => url('admin/store/settings/catalog/edit'),
        '!admin_vocab' => url('admin/content/taxonomy'),
      )),
    );
  }
  return $statuses;
}