| Project: | Ubercart Contributions |
| Component: | Code |
| Category: | task |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | active |
Jump to:
I want to bring to attention that many Ubercart modules are not using the 'product_types' hook when they probably should.
Instead of something like this:
$p_types = module_invoke_all('product_types');
foreach ($p_types as $id) {
$product_types[] = "'". $id ."'";
}
modules are just dipping into the uc_product_class table for a quick look and adding the default 'product'. eg:
$product_types = array("'product'");
$types = db_query("SELECT DISTINCT(pcid) FROM {uc_product_classes}");
One instance of this happening is in uc_reports: function uc_reports_products().
I have brought up this issue because I created a new product type uc_event (a paid event), using the 'product_types' hook implementation and I want to enable uc_reports to report on it. I have modified my uc_reports script in order to make this happen and am requesting that this go to core.
I will report back here on any other instances in uc modules where I think the 'product_types' hook should be used.

This is a good thing to look into, but I want to advise caution because there are good reasons to use each method. hook_product_types() is used to find all the node types that can be used in Ubercart's API. They will have a price and weight, and all that fun stuff.
However, if the code is dealing with the idea that these nodes use the same callbacks to generate information, then you should stick to querying the {uc_product_classes} table. These types use the same node hooks, and they will have the same add to cart forms. They are even more similar too each other than node types that aren't created by uc_product. Like product kits.