You are here

function uc_product_table in Ubercart 6.2

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

Displays product fields in a TAPIr table.

Displays image, name, price, and add to cart form.

6 string references to 'uc_product_table'
hook_tapir_table_alter in docs/hooks.php
Allows modules to alter the TAPIr table after the rows are populated.
hook_tapir_table_header_alter in docs/hooks.php
Allows modules to alter TAPIr table headers.
theme_uc_catalog_products in uc_catalog/uc_catalog.module
Displays a formatted list of products.
uc_product_administration in uc_product/uc_product.admin.inc
Lists all products.
uc_product_table_header in uc_product/uc_product.module
Returns the table header for the product view table.

... See full list

File

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

Code

function uc_product_table($args = array()) {
  $enabled = uc_product_field_enabled();
  $table = array(
    '#type' => 'tapir_table',
    '#attributes' => array(
      'class' => 'category-products',
    ),
    '#columns' => uc_product_table_header(),
    '#rows' => array(),
  );
  $context = array(
    'revision' => 'themed',
    'type' => 'product',
    'class' => array(
      'product',
    ),
  );
  $options = array(
    'label' => FALSE,
  );
  foreach ($args as $nid) {
    $data = array();
    $node = node_load($nid);
    if ($enabled['image']) {
      if (module_exists('imagecache')) {
        if (($field = variable_get('uc_image_' . $node->type, '')) && isset($node->{$field}) && file_exists($node->{$field}[0]['filepath'])) {
          $image = $node->{$field}[0];
          $data['image'] = array(
            '#value' => l(theme('imagecache', 'product_list', $image['filepath'], $image['data']['alt'], $image['data']['title']), 'node/' . $node->nid, array(
              'html' => TRUE,
            )),
          );
        }
        else {
          $data['image'] = array(
            '#value' => t('n/a'),
          );
        }
      }
    }
    $data['name'] = array(
      '#value' => l($node->title, 'node/' . $node->nid),
      '#cell_attributes' => array(
        'width' => '100%',
      ),
    );
    $context['subject'] = array(
      'node' => $node,
    );
    if ($enabled['list_price']) {
      $context['class'][1] = 'list';
      $context['field'] = 'list_price';
      $data['list_price'] = array(
        '#value' => uc_price($node->list_price, $context, $options),
        '#cell_attributes' => array(
          'nowrap' => 'nowrap',
        ),
      );
    }
    if ($enabled['sell_price']) {
      $context['class'][1] = 'sell';
      $context['field'] = 'sell_price';
      $data['price'] = array(
        '#value' => uc_price($node->sell_price, $context, $options),
        '#cell_attributes' => array(
          'nowrap' => 'nowrap',
        ),
      );
    }
    if (module_exists('uc_cart') && arg(0) != 'admin' && $enabled['add_to_cart']) {
      $data['add_to_cart'] = array(
        '#value' => drupal_get_form('uc_catalog_buy_it_now_form_' . $node->nid, $node),
      );
    }
    $table[] = $data;
  }
  if (!count(element_children($table))) {
    $table[] = array(
      'name' => array(
        '#value' => t('No products available.'),
        '#cell_attributes' => array(
          'colspan' => 'full',
        ),
      ),
    );
  }
  return $table;
}