Themeing attributes via uc_product_add_to_cart

4 replies [Last post]
Joined: 05/28/2009
Juice: 38

I hope someone can help me because I'm rather tired of hacking away at this, trying to come up with a solution.

What I am trying to do is apply a theme to uc_product_add_to_cart; specifically, I need to control the placement of attributes in a node. I know there is a theme_uc_product_add_to_cart that I can easily override, but the problem is that a $node reference is passed into the theme function rather than a $form reference. In the default implementation, the theme function pulls the default rendering from drupal_get_form(). I can't seem to find a way to get in between hook_form _alter - which I have implemented with no trouble - and the rendering of the output for the form. Using hook_theme doesn't work because the form_id is different every time. I also tried setting $form['#theme'] in hook_form_alter, but that didn't work either.

I hope this makes sense. Does anyone have any ideas? I would really appreciate the help.

MK

Joined: 05/28/2009
Juice: 38

Well, first of all, I didn't realize there was a uc_attribute_add_to_cart theme. Still, I need to theme the entire add to cart form. I also didn't realize that the #theme attribute had to refer to a function defined in hook_theme().

So, in case anyone else does a similar search and comes across this post, here's what I did.

First, hook_theme():

<?php
function my_module_theme() {
    return array(
       
'add_to_cart_form' => array(
           
'arguments' => array($form => NULL),
        ),
    );
}
?>

Then, hook_form_alter(), with a check to make sure the containing node type was of the type containing the attributes I need to style.

<?php
function my_module_form_alter(&$form, $form_state, $form_id) {
...
    if(
$form['#parameters'][2]->type == 'my_type') {
       
$form['#theme']  = 'add_to_cart_form';
    }
}
?>

And, finally, my theme function, complete with form elements and product attributes.

<?php
function theme_add_to_cart_form($form) {
...
}
?>
Joined: 06/24/2009
Juice: 16

Plz can any one help with a step-by-step, how and where to use the above code

Joined: 05/28/2009
Juice: 38

Do you still need help with this? Let me know. The missing piece may be that you have to create your own module.

Joined: 03/29/2009
Juice: 171

Does the following have to go in template.php?

<?php
function theme_add_to_cart_form($form) {
...
}
?>

Or can you put this somewhere in your module?

I'm trying to package up a module for distribution, and I really don't want users to have to override add a theme function to their theme just to use it.

Thanks for the help!