hook_form_alter()
Adding extra fields to the product (19 replies) Sun, 02/17/2008 - 11:22
- Hi, guys! Please tell me how (09/21/2009 - 18:14)
- Product Installation service as extra (07/29/2009 - 12:08)
- Re: Product Installation service as extra (09/01/2009 - 12:57)
- A website where people can buy information (09/16/2008 - 09:03)
- Drupal formfiler module as an alternative (05/15/2008 - 15:51)
- Re: Adding extra fields to the product (03/20/2008 - 10:20)
- Re: Re: Adding extra fields to the product (03/20/2008 - 12:37)
- hook_form_alter() (03/20/2008 - 17:42)
- Re: hook_form_alter() (04/07/2008 - 19:51)
- Re: Re: hook_form_alter() (04/11/2008 - 17:34)
- Re: hook_form_alter() (04/07/2008 - 19:51)
- hook_form_alter() (03/20/2008 - 17:42)
- Re: Re: Adding extra fields to the product (03/20/2008 - 12:37)
- CCK fields (03/06/2008 - 21:50)
- Re: CCK fields (03/07/2008 - 08:46)
- Re: Re: CCK fields (03/20/2008 - 17:45)
- Re: CCK fields (03/07/2008 - 08:46)
- The magical and wondrous CCK (02/18/2008 - 09:11)
- Re: The magical and wondrous CCK (12/28/2009 - 22:09)
- add field to product (03/19/2008 - 19:05)
- Re: add field to product (03/20/2008 - 08:02)
- Re: Re: add field to product (03/20/2008 - 11:58)
- Re: add field to product (03/20/2008 - 08:02)
- Re: The magical and wondrous CCK (02/19/2008 - 14:17)

That's what I was explaining above. I went this route, and it works ok, I just wish that I could've done it all without having to make a hook_form_alter (I thought ubercart does depend on CCK already, but looking at the project page, it appears it only "recommended", so this makes a little more sense to me, now)
Here's what I did to hide the other price fields (in a custom module):
<?phpfunction YOURMODULE_form_alter($form_id, &$form){
if ($form_id=='YOURNODETYPE_node_form'){
$form['base']['prices']['list_price']['#type'] = 'value';
$form['base']['prices']['cost']['#type'] = 'value';
}
}
?>
Change YOURMODULE to the name of your custom module that you put this function in, and YOURNODETYPE to the content-type for the nodes that you want to modify.
I actually have to do a bunch of other stuff to the edit form (conditional pricing on options, configurable per product, etc), so I am doing some funky copying of CCK values back and forth on hook_form, and an extra _submit function to get it to work the way I want, but this should get you started. I figured out what all needed to be edited by putting a
<?phpdrupal_set_message('<pre>'.var_export($form,TRUE).'</pre>');
?>
in the hook_form_alter function.
As a side-note (but still related, I think) I'd like to realize my dream ecommerce solution, based on these ideas (use CCK for as much as possible, make cart more of a "glue" layer, rather then the main thing, do everything with cck/views/triggers/actions, so you can model your own cart format/flow using standard drupal tools, etc) and would love any advice from e-commerce / ubercart contributors. My target is D6, which appears to make alot of these sort of things a bit easier (triggers/actions in core, rather then requiring workflow-ng)