I was wrong and it feels good

So I’m putting the finishing touches on an UberCart 2 module, and I’m thinking it’s as good as it’s going to get. Then I go ahead and test it—the most visible test would be the creation of a custom node type and product class—and… no go. The class is created, but the node type isn’t.

So I’m putting the finishing touches on an UberCart 2 module, and I’m thinking it’s as good as it’s going to get. Then I go ahead and test it—the most visible test would be the creation of a custom node type and product class—and… no go. The class is created, but the node type isn’t.

After a bit of googling, I realised I’d been doing it the wrong way. My code just had straight db_query‘s to insert the records in {node_type} and {uc_product_classes}. Well, the latter may have been okay, but the former totally wasn’t. db_query does execute correctly, but at some later point the node_type is deleted. Unfortunately I can’t find the particular page that told me this anymore.

Using node_type_save() won’t help, either, since that just calls INSERT or UPDATE commands.

I’ve got options, though. Implementing hook_node_info() and hook_form(), for one, as detailed here. This means I don’t have the option of leaving the node type in the system until the module is uninstalled; also, it still doesn’t answer the question of creating a corresponding product class. I tried adding code to my hook_node_type() implementation to insert the class, but that just had the effect of not creating the node type while creating the product class. Weird.

Still, I’m feeling very positive. This isn’t the first bump I’ve encountered on my Drupal learning curve. Won’t be the last, either, as just today I started porting this module to UberCart 3 / Drupal 7. About time, too, I’ve been itching to dig into D7!