11 replies [Last post]
mk31762's picture
Offline
Joined: 05/28/2009
Juice: 44

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

mk31762's picture
Offline
Joined: 05/28/2009
Juice: 44
Re: Themeing attributes via uc_product_add_to_cart

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) {
...
}
?>
khan_lko's picture
Offline
Joined: 06/24/2009
Juice: 16
Re: Re: Themeing attributes via uc_product_add_to_cart

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

mk31762's picture
Offline
Joined: 05/28/2009
Juice: 44
Re: Re: Re: Themeing attributes via uc_product_add_to_cart

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

jazzdrive3's picture
Offline
Joined: 03/29/2009
Juice: 221
Re: Re: Themeing attributes via uc_product_add_to_cart

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!

autopoietic's picture
Offline
Joined: 07/28/2009
Juice: 52
Re: Re: Themeing attributes via uc_product_add_to_cart

Thanks for that mk31762, saved me some time.

nathan.xiitec (not verified)
nathan.xiitec's picture
theming

I have themed is like this .. if you are interested then let me know

Dominion79's picture
Offline
Joined: 08/08/2010
Juice: 16
Theming product attributes

Hey Nathan,

Any chance you could post up some example code of how you customised your product attributes ?

I'm having some issues sorting this out and any help would really be appreciated

Steve

nathan.xiitec (not verified)
nathan.xiitec's picture
theming
madmadmadaxe's picture
Offline
Joined: 06/28/2010
Juice: 25
Can this get finished?

Someone has asked for step by step instructions for this yet the forum doesn't not have them
People come to this thread looking for an answer. The answer is there and 3 cheers for you for putting it out there.
However it's not understandable by many. FInishing it would be awesome!

jdln's picture
Offline
Joined: 03/08/2010
Juice: 184
Re: Themeing attributes via uc_product_add_to_cart

Subscribing. I need to do this and I couldn't make sense of the instructions. Thanks

jbenjamin's picture
Offline
Joined: 04/14/2009
Juice: 33
Re: Themeing attributes via uc_product_add_to_cart

Has anyone come across a step-by-step on this? I really need to customize some attribute elements, but I'm struggling to get my brain wrapped around this.