views:

69

answers:

1

I'd like to create a product content type from within a module. I followed this very helpful guide to programmatically create a content type. Now how do I "productize" it?

If there already exists a module that does this that I can use to learn from, please do point me in it's direction. Or perhaps there is a guide floating around somewhere?

Thanks!

A: 

I figured it out. Apparently, if you're creating a content type that is also an ubercart product class, you cannot simply follow the tutorial that I linked to above and then "tack on" ubercart stuff. According to the tutorial above, you need to implement the following hooks to create a content type from within your module:

  • hook_info()
  • hook_perm()
  • hook_access()
  • hook_form()
  • hook_help()

To create a content type that is also a product class, you need to make the following modifications to the above list:

  • Remove hook_info(). Not sure why this causes a problem, but it does.
  • Use hook_perm(), hook_access(), hook_form() and hook_help() as usual.
  • Use hook_enable() (which fires when the module is enabled), and include the following code:

    function uc_yourmodule_enable() {
      db_query("INSERT INTO {uc_product_classes} (pcid, name, description) 
                VALUES ('%s', '%s', '%s')", 
                'product_class_id', 
                'Product Class Name', 
                'Product Class Description.');
    
    
      node_types_rebuild();
    }
    

As you can see, the snippet adds an entry to the uc_product_classes table, and I guess that's all ubercart needs.

Finally, I've also implemented an ubercart-specific hook further down in my module: hook_product_types()

I'm just figuring this out as I go along, so I'm happy to receive corrections or suggestions.

ldweeks

related questions