A hook for catalog renderers

Project:Ubercart Contributions
Component:Code
Category:support request
Priority:normal
Assigned:Unassigned
Status:patch (needs review)
Description
Project: 
Ubercart

The attached patches introduces a hook for uc_catalog that enables other modules to define new catalog rendering functions (to render the products in between the sub-terms and pager of a catalog page).
The hook, hook_catalog_display, is similar to hook_menu, and is implemented in the patched version of uc_catalog:

/**
* 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;
}

The only op defined at the moment is 'types'.
The callback function is passed the callback arguments and an array of product nodes and should return the HTML of the catalog page.

The patch modifies the main catalog admin form to add a drop down box with all the defined catalog display types. The selected display type is then used to render catalog pages.

This patch was made to support the uc_multibuy module in order to reduce the amount of code duplication required to render alternative catalog displays. See this module for an additional example of usage of the new hook.

The first patch is for Ubercart-5.x-1.x. The second is for Ubercart 6.x-2.2, and is a multi-file patch.

Version: 
Ubercart 2.x-dev
PreviewAttachmentSize
uc_catalog.module.displaytypes.diff (for 5.x-1.x)5.45 KB
uc_catalog-displaytypes-6.x-2.2.patch (for Ubercart 6.x-2.2)4.72 KB
GreyHawk's picture
Offline
Joined: 03/17/2009
Juice: 174
With the release of Ubercart Beta6, do I need to

re-apply this patch?

I didn't see it listed in the release notes...not sure if it gets overwritten.

Help...! Not sure whether I'll figure it out or not before my client goes live tomorrow! :/

GreyHawk's picture
Offline
Joined: 03/17/2009
Juice: 174
Answer -- YES. Patch must be re-applied.

The Beta6 update over-writes the uc_catalog pieces that the patch updates.

poka_dan's picture
Offline
Joined: 12/16/2009
Juice: 4
Patch FAILED for latest release
Assigned to:GreyHawk» poka_dan

Patch FAILED for ubercart catalog version 6.x-2.2

patching file uc_catalog.module
Hunk #1 succeeded at 193 (offset 14 lines).
Hunk #2 succeeded at 616 (offset 26 lines).
Hunk #3 FAILED at 722.
Hunk #4 succeeded at 726 with fuzz 2 (offset 17 lines).
1 out of 4 hunks FAILED -- saving rejects to file uc_catalog.module.rej
Press any key to continue . . .

Rejects file as follows:

*************** function uc_catalog_get_page($tid) {
*** 685,696 ****
  }
 
  /**
-  * Display a formatted list of products.
   *
   * @param $products
   *   An array of product nids.
   * @return
-  *   A TAPIr table.
   * @ingroup themeable
   */
  function theme_uc_catalog_products($products) {
--- 722,733 ----
  }
 
  /**
+  * Call the catalog rendering function selected by the user.
   *
   * @param $products
   *   An array of product nids.
   * @return
+  *   A catalog page rendered in HTML.
   * @ingroup themeable
   */
  function theme_uc_catalog_products($products) {
poka_dan's picture
Offline
Joined: 12/16/2009
Juice: 4
Re: Patch FAILED for latest release

failed hunks is in comment section so I guess code will work

oliver coleman's picture
Offline
Bug Finder
Joined: 01/09/2008
Juice: 212
Re: A hook for catalog renderers
Assigned to:poka_dan» oliver coleman

Updated patch for 6.x-2.2, no functional changes.

phswartz's picture
Offline
Joined: 02/27/2010
Juice: 43
#6
Category:» support request
Assigned to:oliver coleman» Guest

Please forgive if this seems a stupid question... for the current version -- uc_multibuy-6.x-2.3.tar.gz (for Ubercart 6.x-2.2) -- Is the patch still required? If so, how are patches applied?

Thank you,
Patrick

phswartz's picture
Offline
Joined: 02/27/2010
Juice: 43
#7

I think I have figured out my question on how ...
/sites/all/modules/ubercart/uc_catalog # patch < uc_catalog-displaytypes-6.x-2.2.patch
patching file uc_catalog.admin.inc
patching file uc_catalog.module

If that output is correct, then all is good. If not, please help me understand what I did wrong.
Thank you,
Patrick

MathMan's picture
Offline
Joined: 06/10/2010
Juice: 17
#8

Hi everybody,
Thanks you for the great work Eye-wink
Is this patch compatible with Ubercart 2.3 ?!

MathMan's picture
Offline
Joined: 06/10/2010
Juice: 17
#9

Hi !
I applied the patch "uc_catalog-displaytypes-6.x-2.2.patch" to the uc_catalog-2.3 sub-module and it seems to be compatible, cause differences between "ubercart-2.2" and "ubercart-2.3" do not include "uc_catalog", I think Smiling
Any one to confirm that ?!
Thank you in advance Eye-wink

essbee's picture
Offline
Joined: 07/21/2010
Juice: 29
#10

Yep patch appears fine to me for 2.3. I'm using with multi-but and that all still works.

Sam

Jay August's picture
Offline
Joined: 01/19/2010
Juice: 46
#11

After trying for 4 hours it drives me mad... It's just NOT easy to patch a file under windows7 and therefore I'd like to ask somebody here if they can patch it for me? I use Drupal 6 and UC 2.2

thanks for any help!!

I patched the files myself. Awesome me Smiling
Next up: make this work with Advanced Catalog module......

Stijl9's picture
Offline
Joined: 07/27/2010
Juice: 10
#12

Hi Oliver,

Thanks for all your hard work. I've installed multi-buy and updated the module with te patch. This gives me the possibilty to set te catalog in a multi-buy list table.
But once I view the /catalog/catalog-name page, I don't see any changes (even after clearing the cache).
Am I missing a setting?

I use Drupal 6.19
Ubercart 2.4
And the latest version of multi-buy and it's latest patch.

I hope you can point me in the right direction.

Thanks in advance,

goat_vn's picture
Offline
Joined: 10/24/2010
Juice: 4
#13

How to patch "uc_catalog-displaytypes-6.x-2.2.patch" on a remote hosting? I installed Drupal on Hostgator's hosting and I don't know how to patch this file? Can you help me.
Thanks in advance

andrews501's picture
Offline
Joined: 11/15/2010
Juice: 71
#14

Hello,

Great module. I am testing it in drupal 6.19 and ubercart 6.2.4. and noticed the following message:

Warning: Call-time pass-by-reference has been deprecated in /hsphere/local/home/ecosystems/britmex.co.uk/sites/all/modules/uc_multibuy/uc_multibuy.module on line 295 Warning: Call-time pass-by-reference has been deprecated in /hsphere/local/home/ecosystems/website.co.uk/sites/all/modules/uc_multibuy/uc_multibuy.module on line 295

When:

//apply known form alterations (but not any and all because they all need special handling)
if ($product->type == 'donation') {
uc_donation_form_alter(&$form, &$form_state, $form_id);
}

I installed uc_donation but the warning didnt disapear. So I commented the following lines and the warning disapeared:

//apply known form alterations (but not any and all because they all need special handling)
// if ($product->type == 'donation') {
// uc_donation_form_alter(&$form, &$form_state, $form_id);
// }

As I have many products in six categories, I would like to put them all in one multibuy grid in my frontpage, any suggestion on how this can be achieved, please?

Many thanks!

ergophobe's picture
Offline
Joined: 06/21/2010
Juice: 115
#15

>>Call-time pass-by-reference has been deprecated

This is an issue with PHP - pass by reference is deprecated in PHP 5, but since Drupal is not fully PHP 5 until Drupal 7, you'll get these warnings. You can

- change your error message settings to not show E_WARNING or perhaps exclude just E_DEPRECATED
- set allow_call_time_pass_reference on in your php.ini (http://php.net/manual/en/ini.core.php)

jrotondo's picture
Offline
Joined: 03/17/2010
Juice: 6
#16

Patch rejected using D6 and UC6.x-2.9
patching file uc_catalog.admin.inc
Hunk #1 succeeded at 41 with fuzz 1 (offset -1 lines).
Hunk #2 FAILED at 71.
Hunk #3 succeeded at 176 (offset 9 lines).
Hunk #4 succeeded at 186 (offset 9 lines).
1 out of 4 hunks FAILED -- saving rejects to file uc_catalog.admin.inc.rej
patching file uc_catalog.module
Hunk #2 succeeded at 629 (offset 13 lines).
Hunk #3 FAILED at 731.
1 out of 3 hunks FAILED -- saving rejects to file uc_catalog.module.rej

Rejected code for uc_catalog.admin.inc

***************
*** 66,71 ****
      ),
      '#default_value' => variable_get('uc_catalog_breadcrumb', TRUE),
    );
    $form['catalog-top-level']['uc_catalog_breadcrumb_nodecount'] = array('#type' => 'checkbox',
      '#title' => t('Display node counts in the catalog breadcrumb'),
      '#summary callback' => 'summarize_checkbox',
--- 71,83 ----
      ),
      '#default_value' => variable_get('uc_catalog_breadcrumb', TRUE),
    );
+   $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_nodecount'] = array('#type' => 'checkbox',
      '#title' => t('Display node counts in the catalog breadcrumb'),
      '#summary callback' => 'summarize_checkbox',

Rejected code for uc_catalog.module

***************
*** 702,720 ****
      $output .= '<div class="no-products">'. t('No products are available in this category.') .'</div>';
      return $output;
    }
-   else {
-     if (variable_get('uc_catalog_grid_display', FALSE)) {
-       return theme('uc_catalog_product_grid', $products);
-     }
-     else {
-       $table = tapir_get_table('uc_product_table', $products);
-       return drupal_render($table);
-     }
-   }
  }
 
  /**
-  * Display a list of products in grid format().
   *
   * @ingroup themeable
   */
--- 731,755 ----
      $output .= '<div class="no-products">'. t('No products are available in this category.') .'</div>';
      return $output;
    }
+   $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);
+ }
+
+ /**
+  * Display a list of products in table format.
+  *
+  * @ingroup themeable
+  */
+ function theme_uc_catalog_product_table($products) {
+   $table = tapir_get_table('uc_product_table', $products);
+   return drupal_render($table);
  }
 
  /**
+  * Display a list of products in grid format.
   *
   * @ingroup themeable
   */

Any ideas why this failed? I'd LOVE to be able to use the Multi-Buy module!