--- uc_catalog.module 2008-05-17 06:30:51.000000000 +1000
+++ uc_catalog.module.displaytypes 2008-05-30 18:00:57.000000000 +1000
@@ -546,12 +546,15 @@ function uc_catalog_product_class($type,
function uc_catalog_settings_overview() {
$sections = array();
+ $display_options = array_merge(module_invoke_all('catalog_display', 'types'));
+
$sections[] = array(
'edit' => 'admin/store/settings/catalog/edit',
'title' => t('Catalog settings'),
'items' => array(
t('The catalog vocabulary id is !vid.',
array('!vid' => variable_get('uc_catalog_vid', 0))),
+ t('The display format of the catalog is '). t($display_options[variable_get('uc_catalog_display_type', 'default_table')]['name']),
t('The base URL pointing to the catalog is !url.',
array('!url' => 'catalog')),
variable_get('uc_catalog_breadcrumb', true) ?
@@ -567,9 +570,6 @@ function uc_catalog_settings_overview()
'edit' => 'admin/store/settings/catalog/edit/grid',
'title' => t('Products grid settings'),
'items' => array(
- variable_get('uc_catalog_grid_display', false) ?
- t('The catalog will be displayed on a grid.') :
- t('The catalog will be displayed on a table list.'),
format_plural(variable_get('uc_catalog_grid_display_width', 3), 'The grid will be displayed in @count column.', 'The grid will be displayed in @count columns.'),
variable_get('uc_catalog_grid_display_title', true) ?
t('Every cell on the grid will display the Product Title.') :
@@ -939,12 +939,37 @@ function theme_uc_catalog_browse($tid =
}
/**
- * Display a formatted list of products.
+ * Implementation of hook_catalog_display
+ *
+ * @return
+ * An array specifying catalog display types
+ */
+function uc_catalog_catalog_display($op) {
+ switch ($op) {
+ case 'types':
+ $return = array();
+ $return['default_table'] = array(
+ 'name' => 'Default list table',
+ 'callback' => 'theme',
+ 'callback arguments' => 'uc_catalog_products_table'
+ );
+ $return['grid'] = array(
+ 'name' => 'Grid',
+ 'callback' => 'theme',
+ 'callback arguments' => 'uc_catalog_product_grid'
+ );
+ break;
+ }
+ return $return;
+}
+
+/**
+ * Call the catalog rendering function selected by the user.
*
* @param $products
* An array of product nids.
* @return
- * A TAPIr table.
+ * A catalog page rendered in HTML.
* @ingroup themeable
*/
function theme_uc_catalog_products($products) {
@@ -952,16 +977,18 @@ function theme_uc_catalog_products($prod
$output .= '
'. t('No products are available in this category.') .'
';
return $output;
}
- else {
- if (variable_get('uc_catalog_grid_display', false)) {
- return theme('uc_catalog_product_grid', $products);
+
+ $display_types = module_invoke_all('catalog_display', 'types');
+ $display_type = $display_types[variable_get('uc_catalog_display_type', 'default_table')];
+ $args = (array) $display_type['callback arguments'];
+ $args[] = $products;
+ return call_user_func_array($display_type['callback'], $args);
}
- else {
+
+function theme_uc_catalog_products_table($products) {
$table_args = array('nids' => $products, 'attributes' => array('class' => 'category-products'));
return tapir_get_table('uc_product_table', $table_args);
}
- }
-}
function theme_uc_catalog_product_grid($products) {
$product_table = '';
@@ -1031,6 +1058,11 @@ function uc_catalog_admin_form() {
$vocabs[$vid] = $vocabulary->name;
}
+ $display_types = array_merge(module_invoke_all('catalog_display', 'types'));
+ $display_options = array();
+ foreach($display_types as $type => $info)
+ $display_options[$type] = $info['name'];
+
// JTR - catalog-top-level sub-textfield
$form['catalog-top-level'] = array('#type' => 'fieldset',
'#title' => t('Catalog top level'),
@@ -1044,6 +1076,13 @@ function uc_catalog_admin_form() {
'#default_value' => variable_get('uc_catalog_vid', 0),
'#options' => $vocabs,
);
+ $form['catalog-top-level']['uc_catalog_display_type'] = array(
+ '#type' => 'select',
+ '#title' => t('Catalog display format'),
+ '#description' => t("Select how products in the catalog will be displayed."),
+ '#default_value' => variable_get('uc_catalog_display_type', 'default_table'),
+ '#options' => $display_options,
+ );
$form['catalog-top-level']['uc_catalog_breadcrumb'] = array('#type' => 'checkbox',
'#title' => t('Display the catalog breadcrumb'),
'#default_value' => variable_get('uc_catalog_breadcrumb', true),
@@ -1062,6 +1101,8 @@ function uc_catalog_admin_form() {
'#options' => drupal_map_assoc(uc_range(1, 5)),
);
+
+
$form['block-display'] = array('#type' => 'fieldset',
'#title' => t('Catalog block settings'),
'#collapsible' => true,
@@ -1117,12 +1158,6 @@ function uc_catalog_grid_admin_form() {
'#weight' => -3,
'#attributes' => array('class' => 'catalog-grid'),
);
- $form['catalog-grid']['uc_catalog_grid_display'] = array(
- '#type' => 'checkbox',
- '#title' => t('Display products in grid'),
- '#default_value' => variable_get('uc_catalog_grid_display', false),
- '#description' => t("Select it if you want the products to be displayed on a grid instead of a list table."),
- );
$form['catalog-grid']['uc_catalog_grid_display_width'] = array(
'#type' => 'textfield',
'#title' => t('Width of grid'),