hook_form_alter()

konsumer's picture
Offline
Joined: 03/06/2008
Juice: 6
hook_form_alter()

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):

<?php
function 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

<?php
drupal_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)

Adding extra fields to the product By: sajt (30 replies) Sun, 02/17/2008 - 11:22