Creating additional catalog blocks in Ubercart for Drupal 6
When using the traditional Ubercart catalog module, I have run into the problem of needing to classify and display products in multiple catalogs. You would think I could just create a block of the taxonomy terms, however that will create links to the taxonomy term pages and the display for that is vastly different than the catalog display.
Here is my quick solution. I basically create another catalog block. This will open up the products in my secondary taxonomy vocabulary (that I am using as an additional catalog), using the traditional Ubercart catalog layout/design.
The code is really pretty simple and is taken mostly from the uc_catalog.module file.
/** * Implementation of hook_block(). */ function MYMODULE_block($op = 'list', $delta = 0, $edit = array()) { switch ($op) { case 'list': $blocks[0]['info'] = t('MY NEW Catalog Block'); return $blocks; case 'view': switch ($delta) { case 0: drupal_add_css(drupal_get_path('module', 'uc_catalog') .'/uc_catalog.css'); // Hardcode the vocabulary for the new catalog block $vid = 5; $tree = taxonomy_get_tree($vid); // Then convert it into an actual tree structure. $seq = 0; $menu_tree = new UcTreeNode(); $level = array(); $curr_depth = -1; foreach ($tree as $knot) { $seq++; $knot->sequence = $seq; $knothole = new UcTreeNode($knot); // Begin at the root of the tree and find the proper place. $menu_tree->add_child($knothole); } // Now, create a structured menu, separate from Drupal's menu. $content = theme('uc_catalog_block', $menu_tree); $subject = t('New Catalog Title Goes Here'); $block = array('subject' => $subject, 'content' => $content); return $block; break; } break; } }
The code above should be almost drop in and go. You just need to replace the $vid variable with the correct vocabulary id, replace the module name in the hook, and change up the text/titles as you see fit.



Discussions
santa
An Ubercart E-commerce website built with Drupal six and need to need theme different catalog pages differently, you are not alone. I recently ran into a situation that required links to be a different color on a specific catalog page. That part was fairly easy as there were unique body classes available for each page. However, it was not intuitive getting all the children terms of that catalog page to show up the same way. Thanks.
Regards,
Thanks, this is just what I
Thanks, this is just what I was after. Question tho: Where do I drop in this code?
Custom module
You will need to put this code inside a custom module. If you are unfamiliar with creating your own custom module, this might help http://drupal.org/node/231276.
After creating the module and dropping in this code, make sure to change "MYMODULE_block" on line 4 of the code above, to accurately represent whatever you name your module.
Post new comment