Currently if you create a product in UberCart, you have to first create the product before accessing t开发者_运维技巧he stock tab to set stock levels. I want to be able to set the stock levels when I create the product. I.e. Right below where I set the "list price". How would I do this?
Well, that's going to involve a little work.
- You're going to have to create a hook_form_alter implementation to add the new form fields to the node_add/node_edit form.
- You're going to want to add a hook_nodeapi() implementation for $op=='validate' to make sure you're getting valid information.
- You're then going to want to extend that hook_nodeapi() implementation for $op=='insert' and 'update' to grab the field value (which should be stuck to the $node object) and write it to the stock levels table, whose name I'm too lazy to look up right now.
Alternately, instead of 2 and 3, you could mess around with creating a validation and submit function, and append them to the #validate and #submit arrays of the form.
For people looking for a module-based solution to this problem in Drupal 7, the latest dev version of the "Ubercart Product Power Tools" module has an excellent per-product setting to make stock-tracking active on creation, as well as set default stock quantity and threshold for the product.
- Ubercart Product Power Tools
精彩评论