Drupal 6 Ubercart Theme Add to Cart Form

By shane
Fri, 2012-05-11 18:37
15 comments

So you need to theme, customize, or change the Add to cart form that is output by Ubercart? If so, read on for more information. If you are looking to change the general theme or style of the Ubercart product node page, then you might want to look at my post on theming Ubercart Product Page for Drupal 6.

I needed to heavily modify the Ubercart add to cart form for one specific product content type. This example is set up to show how to theme the Ubercart add to cart form for one specific content type (in this example it is the product content type).

Step 1: Create custom Drupal 6 module

I called my custom Drupal 6 module uc_alterations, but you can pick your own name if you are feeling creative.

First step is to create the module folder, in my case I called it uc_alterations. Then it is time to create the info file (called uc_alterations.info). Here are the contents of my info file:


core = "6.x"
dependencies[] = "uc_cart"
description = "Ubercart Add to Cart Form Alterations"
name = "Ubercart Add to Cart Form Alterations"
version = "6.x-1.0"

Step 2: Add Drupal 6 form_alter and theme functions to module

Now its time to create the module file (called uc_alterations.module). In this module file you will need to implement hook_theme, and hook_form_alter.

Here are the contents of my module file:

/**
 * Implements hook_form_alter().
 */
function uc_alterations_form_alter(&$form, &$form_state, $form_id) {
  if(stripos($form_id, 'uc_product_add_to_cart_form') === 0 && $form['#parameters'][2]->type == 'product') {
    $form['#theme']  = 'uc_alterations_add_to_cart';
  }
}
 
/**
 * Implements hook_theme().
 */
function uc_alterations_theme() {
  return array(
    'uc_alterations_add_to_cart' => array(
      'arguments' => array('form' => NULL),
      'template' => 'uc_alterations_form',
    ),
  );
}

Step 3: Add Drupal 6 template file to module

In this instance I decided to use a separate template file. If I would have preferred to use a theme function, I simply would have left out the template line in the hook_theme definition and added a function to the module file similar to the one below:

function theme_uc_alterations_add_to_cart($form) {
  //all my form theming goes here
  return drupal_render($form);
}

Since I decided to use the template approach, I created a file inside my module directory called uc_alterations_form.tpl.php. Here is an example of how that file might look:

<?php
/**
 * Template for theming the add to cart form for product products
 *
 * Available Variables:
 *   $form - contains the form array containing the product attributes
 */
//You can view the form variable by uncommenting this line
//print('<pre>'.print_r($form,1).'</pre>');
?>
<div class="product-wrapper">
  <div class="product-info-wrapper">
    <div><?php print drupal_render($form['attributes'][1]); ?></div>
    <div><?php print drupal_render($form['attributes'][5]); ?></div>
    <div><?php print drupal_render($form['attributes'][2]); ?></div>
  </div>
  <?php print drupal_render($form); ?>
</div>

You will notice that to print out the attributes you need to pull out the specific attribute ID, in this case, 1, 5, and 2. This can cause issues if you have a different development/testing environment if the attribute ID's are not exactly the same, however for some cases, this is an acceptable solution. If you need to make this work with varying attribute ID's, you will need to create some type of lookup function based on the attribute title (or another column in the table that will match up despite differing attribute ID's). Since that is a little out of the scope of this post, and this solution was acceptable in my situation, I will leave that out for now.

You will also note that at the bottom of the Drupal 6 template file, I print out the rest of the form using drupal_render. This will print out the hidden form attributes such as form id, as well as the Add to Cart button.

So there you have it, you can now theme your Drupal 6 Ubercart add to cart form.

Need to learn more Drupal?

Premium Drupal Training Online (Horizontal)

Comments

Hey man...

This is an awesome post and really helped me out!

I am a front end themer and until now not really got to deep into pre process, hook form alter etc....

And certainly have never build a custom module!!

It appears by following your post I have now!! :)

I am stuck with two things:

1. How would I theme the actual 'Add to Cart' button to use a custom image (css background image) and change the value of the button?

Would css work for the image? But what about the value?

2. I dont seem to be able to print out my Price variable from withing my new uc_alterations module using this:

 print $node->content['display_price']['#value']

Any ideas?

This is my full uc_alterations_form.tpl.php:

<div class="product-wrapper">
  <div class="product-info-wrapper">
    <div class="color-attribute"><?php print drupal_render($form['attributes'][1]); ?></div>
    <div class="clearfix">
    	<div id="uc_product_price" class="clearfix">
        	<div class="label">Price</div>
            <div class="product_attribute"><?php print $node->content['display_price']['#value'] ?></div> 
        </div>
    	<div id="buy_now"><?php print drupal_render($form); ?></div>
    </div>
  </div>

You can see what I am trying to do here:

staging.anchorguitars.com/content/tall-ship-les-paul

Your help would be amazing right now!!!

Thanks again....

Great site!!!

Ryan (gibry21)

For question 1:

Inside the form_alter function you created, you should be able to set the submit button value. This code might help you debug the form variable to find out where the submit button is located.

print('<pre>'.print_r($form,1).'</pre>');

This is most likely going to be at $form['submit'] so something like this might work to change the value:

$form['submit']['#value'] = t('My Add to Cart Button');

I generally just use CSS for submit button images.

For question 2:

I am not exactly sure what you are trying to do, but perhaps something like this would work.

print $form['#node']->content['display_price']['#value']

My guess is the $node variable does not exist inside your uc_alterations_form.tpl.php, however I think the $form variable probably has what you need. You could try this to see:

print('<pre>'.print_r($form,1).'</pre>');

Thanks...

I think I got Q1...as I thought css should do it....why complicate it!

As for Q2 I tried your suggestion which was similar to what I though but still nothing is being printed....I know I am close....but my php just aint good enough to know how to drill into this array and print what I need!!

I know this is working and printing my colour options box as expected:

 print drupal_render($form['attributes'][1]);

But I just cant seem to be able to print the display price! I can see it in several places in the form array but just cant get it out!!

Sorry for the big code dump....here is my form arrray....please help!!!

Gibry21


Array
(
[attributes] => Array
(
[1] => Array
(
[#type] => select
[#description] =>
[#default_value] =>
[#options] => Array
(
[] => Please select
[2] =>
Old White

[1] =>
Natural

)

[#required] => 1
[#title] => Color
[#post] => Array
(
)

[#programmed] =>
[#tree] => 1
[#parents] => Array
(
[0] => attributes
[1] => 1
)

[#array_parents] => Array
(
[0] => attributes
[1] => 1
)

[#weight] => 0
[#processed] => 1
[#attributes] => Array
(
)

[#input] => 1
[#size] => 0
[#multiple] =>
[#process] => Array
(
[0] => form_expand_ahah
)

[#name] => attributes[1]
[#id] => edit-attributes-1
[#value] =>
[#defaults_loaded] => 1
[#sorted] => 1
[#printed] => 1
)

[#theme] => uc_attribute_add_to_cart
[#tree] => 1
[#weight] => -1
[#post] => Array
(
)

[#programmed] =>
[#parents] => Array
(
[0] => attributes
)

[#array_parents] => Array
(
[0] => attributes
)

[#processed] =>
[#defaults_loaded] => 1
[#sorted] => 1
[#title] =>
[#description] =>
[#theme_used] => 1
[#value] =>
[#type] =>
[#prefix] =>
[#suffix] =>
[#children] =>

[#printed] => 1
)

[#defaults_loaded] => 1
[#submit] => Array
(
[0] => uc_product_add_to_cart_form_submit
)

[nid] => Array
(
[#type] => value
[#value] => 185
[#post] => Array
(
)

[#programmed] =>
[#tree] =>
[#parents] => Array
(
[0] => nid
)

[#array_parents] => Array
(
[0] => nid
)

[#weight] => 0
[#processed] =>
[#description] =>
[#attributes] => Array
(
)

[#required] =>
[#input] => 1
[#name] => nid
[#id] => edit-nid
[#defaults_loaded] => 1
[#sorted] => 1
[#title] =>
[#printed] => 1
)

[#build_id] => form-2f0745aa119a6f7c32c123d4e96f9249
[#after_build_done] => 1
[#type] => markup
[#theme_used] => 1
[#value] =>
[#title] =>
[#programmed] =>
[#token] => uc_product_add_to_cart_form_185
[#processed] =>
[#parameters] => Array
(
[0] => uc_product_add_to_cart_form_185
[1] => Array
(
[storage] =>
[submitted] =>
[post] => Array
(
)

)

[2] => stdClass Object
(
[nid] => 185
[type] => anchor_guitars
[language] =>
[uid] => 1
[status] => 1
[created] => 1341004421
[changed] => 1343323777
[comment] => 0
[promote] => 0
[moderate] => 0
[sticky] => 0
[tnid] => 0
[translate] => 0
[vid] => 185
[revision_uid] => 1
[title] => Tall Ship (les paul)
[body] =>

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent rutrum, tellus sed sodales elementum, urna ipsum elementum nisl, quis tincidunt nunc quam a justo. Nunc quis iaculis turpis. Quisque mollis pulvinar odio quis vulputate. Phasellus lacinia augue eget mi aliquam rhoncus.

[teaser] => Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent rutrum, tellus sed sodales elementum, urna ipsum elementum nisl, quis tincidunt nunc quam a justo. Nunc quis iaculis turpis.
[log] =>
[revision_timestamp] => 1343323777
[format] => 2
[name] => gibry21
[picture] =>
[data] => a:2:{s:7:"contact";i:0;s:13:"form_build_id";s:37:"form-c4417898cb93696cc0bbbd4b68d80a13";}
[model] => aeg_tallship_01
[list_price] => 1199.00000
[cost] => 1199.00000
[sell_price] => 1199.00000
[weight] => 0
[weight_units] => lb
[length] => 0
[width] => 0
[height] => 0
[length_units] => in
[pkg_qty] => 1
[default_qty] => 1
[unique_hash] => 64f078337889222f51e5d07ec5a3681c
[ordering] => 0
[shippable] => 1
[path] => content/tall-ship-les-paul
[field_image_cache] => Array
(
[0] => Array
(
[fid] => 750
[uid] => 1
[filename] => lighthouse-2.jpg
[filepath] => sites/default/files/lighthouse-2_1.jpg
[filemime] => image/jpeg
[filesize] => 18388
[status] => 1
[timestamp] => 1341004326
[list] => 1
[data] => Array
(
[alt] =>
[title] =>
)

)

[1] => Array
(
[fid] => 751
[uid] => 1
[filename] => lighthouse-1.jpg
[filepath] => sites/default/files/lighthouse-1_1.jpg
[filemime] => image/jpeg
[filesize] => 38925
[status] => 1
[timestamp] => 1341004335
[list] => 1
[data] => Array
(
[alt] =>
[title] =>
)

)

[2] => Array
(
[fid] => 752
[uid] => 1
[filename] => lighthouse-3.jpg
[filepath] => sites/default/files/lighthouse-3_1.jpg
[filemime] => image/jpeg
[filesize] => 46225
[status] => 1
[timestamp] => 1341004350
[list] => 1
[data] => Array
(
[alt] =>
[title] =>
)

)

[3] => Array
(
[fid] => 753
[uid] => 1
[filename] => lighthouse-4.jpg
[filepath] => sites/default/files/lighthouse-4_1.jpg
[filemime] => image/jpeg
[filesize] => 25347
[status] => 1
[timestamp] => 1341004362
[list] => 1
[data] => Array
(
[alt] =>
[title] =>
)

)

)

[field_body_style] => Array
(
[0] => Array
(
[value] => single cut, carved top, cream binding
)

)

[field_body_species] => Array
(
[0] => Array
(
[value] => mahogany body, plain solid maple top, 1 11/16 thick
)

)

[field_tuners] => Array
(
[0] => Array
(
[value] => grover
)

)

[field_pick_up] => Array
(
[0] => Array
(
[value] => 1 neck humbucker, 1 bridge humbucker
)

)

[field_neck] => Array
(
[0] => Array
(
[value] => mahogany, thick “C” neck profile
)

)

[field_finish] => Array
(
[0] => Array
(
[value] => thin lacquer
)

)

[field_screen_print] => Array
(
[0] => Array
(
[value] => tall ship
)

)

[field_fretboard] => Array
(
[0] => Array
(
[value] => ebony, 12” radius, 24.75 scale, 5mm pearloid markers
)

)

[field_frets] => Array
(
[0] => Array
(
[value] => 22 medium jumbo
)

)

[field_headstock] => Array
(
[0] => Array
(
[value] => 11 degree exaggerated gibson style, scarf joint
)

)

[field_nut_width] => Array
(
[0] => Array
(
[value] => 1 11/16”
)

)

[field_neck_joint] => Array
(
[0] => Array
(
[value] => set neck tenon
)

)

[field_truss_rod] => Array
(
[0] => Array
(
[value] => dual action stainless steel
)

)

[field_controls] => Array
(
[0] => Array
(
[value] => neck volume, neck tone, bridge volume, bridge tone, 3 way switch
)

)

[field_pickguard] => Array
(
[0] => Array
(
[value] => Black
)

)

[field_bridge] => Array
(
[0] => Array
(
[value] => gibson style tunomatic stop bar bridge
)

)

[attributes] => Array
(
[1] => stdClass Object
(
[aid] => 1
[name] => Anchor Guitar Color
[default_label] => Color
[default_ordering] => 0
[default_required] => 0
[default_display] => 1
[description] =>
[label] => Color
[default_option] =>
[required] => 1
[ordering] => 0
[display] => 1
[nid] => 185
[options] => Array
(
[2] => stdClass Object
(
[nid] => 185
[oid] => 2
[cost] => 0.00000
[price] => 0.00000
[weight] => 0
[ordering] => -1
[name] => Old White
[aid] => 1
)

[1] => stdClass Object
(
[nid] => 185
[oid] => 1
[cost] => 0.00000
[price] => 0.00000
[weight] => 0
[ordering] => 0
[name] => Natural
[aid] => 1
)

)

)

)

[taxonomy] => Array
(
[15] => stdClass Object
(
[tid] => 15
[vid] => 3
[name] => Anchor Electric Guitars
[description] => Category for the 3 types of Anchor guitar:

Steadfast
Homeward
Tall Ship
[weight] => 0
)

)

[page_title] =>
[shipping_type] => small_package
[shipping_address] => stdClass Object
(
)

[ups] => Array
(
[vid] => 185
[nid] => 185
[pkg_type] => 02
)

[build_mode] => 0
[readmore] => 1
[content] => Array
(
[body] => Array
(
[#value] =>

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent rutrum, tellus sed sodales elementum, urna ipsum elementum nisl, quis tincidunt nunc quam a justo. Nunc quis iaculis turpis. Quisque mollis pulvinar odio quis vulputate. Phasellus lacinia augue eget mi aliquam rhoncus.

[#weight] => 1
)

[image] => Array
(
[#value] =>

[#access] => 1
[#weight] => 1
)

[display_price] => Array
(
[#value] =>

$1,199.00

[#access] => 1
[#weight] => -1
)

[model] => Array
(
[#value] =>

SKU: aeg_tallship_01

[#access] => 0
[#weight] => 0
)

[list_price] => Array
(
[#value] =>

List Price: $1,199.00

[#access] => 0
[#weight] => 2
)

[cost] => Array
(
[#value] =>

Cost: $1,199.00

[#access] =>
[#weight] => 3
)

[sell_price] => Array
(
[#value] =>

Price: $1,199.00

[#access] => 1
[#weight] => 4
)

[weight] => Array
(
[#value] =>

Weight: 0 lb.

[#access] => 0
[#weight] => 5
)

[dimensions] => Array
(
[#value] =>

Dimensions: 0in. × 0in. × 0in.

[#access] => 0
[#weight] => 6
)

)

)

)

[#validate] => Array
(
[0] => uc_product_add_to_cart_form_validate
)

[#id] => uc-product-add-to-cart-form-185
[#attributes] => Array
(
)

[#tree] =>
[#required] =>
[#parents] => Array
(
)

[#description] =>
[#theme] => uc_alterations_add_to_cart
[#post] => Array
(
)

[#action] => /content/tall-ship-les-paul
[#after_build] => Array
(
[0] => wysiwyg_process_form
)

[#method] => post
[qty] => Array
(
[#type] => hidden
[#value] => 1
[#post] => Array
(
)

[#programmed] =>
[#tree] =>
[#parents] => Array
(
[0] => qty
)

[#array_parents] => Array
(
[0] => qty
)

[#weight] => 0.001
[#processed] => 1
[#description] =>
[#attributes] => Array
(
)

[#required] =>
[#input] => 1
[#process] => Array
(
[0] => form_expand_ahah
)

[#name] => qty
[#id] => edit-qty
[#defaults_loaded] => 1
[#sorted] => 1
[#title] =>
[#printed] => 1
)

[submit] => Array
(
[#type] => submit
[#value] => Add to cart
[#id] => edit-submit-185
[#attributes] => Array
(
[class] => node-add-to-cart
)

[#post] => Array
(
)

[#programmed] =>
[#tree] =>
[#parents] => Array
(
[0] => submit
)

[#array_parents] => Array
(
[0] => submit
)

[#weight] => 0.002
[#processed] => 1
[#description] =>
[#required] =>
[#input] => 1
[#name] => op
[#button_type] => submit
[#executes_submit_callback] => 1
[#process] => Array
(
[0] => form_expand_ahah
)

[#defaults_loaded] => 1
[#sorted] => 1
[#title] =>
[#printed] => 1
)

[node] => Array
(
[#type] => value
[#value] => stdClass Object
(
[nid] => 185
[type] => anchor_guitars
[language] =>
[uid] => 1
[status] => 1
[created] => 1341004421
[changed] => 1343323777
[comment] => 0
[promote] => 0
[moderate] => 0
[sticky] => 0
[tnid] => 0
[translate] => 0
[vid] => 185
[revision_uid] => 1
[title] => Tall Ship (les paul)
[body] =>

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent rutrum, tellus sed sodales elementum, urna ipsum elementum nisl, quis tincidunt nunc quam a justo. Nunc quis iaculis turpis. Quisque mollis pulvinar odio quis vulputate. Phasellus lacinia augue eget mi aliquam rhoncus.

[teaser] => Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent rutrum, tellus sed sodales elementum, urna ipsum elementum nisl, quis tincidunt nunc quam a justo. Nunc quis iaculis turpis.
[log] =>
[revision_timestamp] => 1343323777
[format] => 2
[name] => gibry21
[picture] =>
[data] => a:2:{s:7:"contact";i:0;s:13:"form_build_id";s:37:"form-c4417898cb93696cc0bbbd4b68d80a13";}
[model] => aeg_tallship_01
[list_price] => 1199.00000
[cost] => 1199.00000
[sell_price] => 1199.00000
[weight] => 0
[weight_units] => lb
[length] => 0
[width] => 0
[height] => 0
[length_units] => in
[pkg_qty] => 1
[default_qty] => 1
[unique_hash] => 64f078337889222f51e5d07ec5a3681c
[ordering] => 0
[shippable] => 1
[path] => content/tall-ship-les-paul
[field_image_cache] => Array
(
[0] => Array
(
[fid] => 750
[uid] => 1
[filename] => lighthouse-2.jpg
[filepath] => sites/default/files/lighthouse-2_1.jpg
[filemime] => image/jpeg
[filesize] => 18388
[status] => 1
[timestamp] => 1341004326
[list] => 1
[data] => Array
(
[alt] =>
[title] =>
)

)

[1] => Array
(
[fid] => 751
[uid] => 1
[filename] => lighthouse-1.jpg
[filepath] => sites/default/files/lighthouse-1_1.jpg
[filemime] => image/jpeg
[filesize] => 38925
[status] => 1
[timestamp] => 1341004335
[list] => 1
[data] => Array
(
[alt] =>
[title] =>
)

)

[2] => Array
(
[fid] => 752
[uid] => 1
[filename] => lighthouse-3.jpg
[filepath] => sites/default/files/lighthouse-3_1.jpg
[filemime] => image/jpeg
[filesize] => 46225
[status] => 1
[timestamp] => 1341004350
[list] => 1
[data] => Array
(
[alt] =>
[title] =>
)

)

[3] => Array
(
[fid] => 753
[uid] => 1
[filename] => lighthouse-4.jpg
[filepath] => sites/default/files/lighthouse-4_1.jpg
[filemime] => image/jpeg
[filesize] => 25347
[status] => 1
[timestamp] => 1341004362
[list] => 1
[data] => Array
(
[alt] =>
[title] =>
)

)

)

[field_body_style] => Array
(
[0] => Array
(
[value] => single cut, carved top, cream binding
)

)

[field_body_species] => Array
(
[0] => Array
(
[value] => mahogany body, plain solid maple top, 1 11/16 thick
)

)

[field_tuners] => Array
(
[0] => Array
(
[value] => grover
)

)

[field_pick_up] => Array
(
[0] => Array
(
[value] => 1 neck humbucker, 1 bridge humbucker
)

)

[field_neck] => Array
(
[0] => Array
(
[value] => mahogany, thick “C” neck profile
)

)

[field_finish] => Array
(
[0] => Array
(
[value] => thin lacquer
)

)

[field_screen_print] => Array
(
[0] => Array
(
[value] => tall ship
)

)

[field_fretboard] => Array
(
[0] => Array
(
[value] => ebony, 12” radius, 24.75 scale, 5mm pearloid markers
)

)

[field_frets] => Array
(
[0] => Array
(
[value] => 22 medium jumbo
)

)

[field_headstock] => Array
(
[0] => Array
(
[value] => 11 degree exaggerated gibson style, scarf joint
)

)

[field_nut_width] => Array
(
[0] => Array
(
[value] => 1 11/16”
)

)

[field_neck_joint] => Array
(
[0] => Array
(
[value] => set neck tenon
)

)

[field_truss_rod] => Array
(
[0] => Array
(
[value] => dual action stainless steel
)

)

[field_controls] => Array
(
[0] => Array
(
[value] => neck volume, neck tone, bridge volume, bridge tone, 3 way switch
)

)

[field_pickguard] => Array
(
[0] => Array
(
[value] => Black
)

)

[field_bridge] => Array
(
[0] => Array
(
[value] => gibson style tunomatic stop bar bridge
)

)

[attributes] => Array
(
[1] => stdClass Object
(
[aid] => 1
[name] => Anchor Guitar Color
[default_label] => Color
[default_ordering] => 0
[default_required] => 0
[default_display] => 1
[description] =>
[label] => Color
[default_option] =>
[required] => 1
[ordering] => 0
[display] => 1
[nid] => 185
[options] => Array
(
[2] => stdClass Object
(
[nid] => 185
[oid] => 2
[cost] => 0.00000
[price] => 0.00000
[weight] => 0
[ordering] => -1
[name] => Old White
[aid] => 1
)

[1] => stdClass Object
(
[nid] => 185
[oid] => 1
[cost] => 0.00000
[price] => 0.00000
[weight] => 0
[ordering] => 0
[name] => Natural
[aid] => 1
)

)

)

)

[taxonomy] => Array
(
[15] => stdClass Object
(
[tid] => 15
[vid] => 3
[name] => Anchor Electric Guitars
[description] => Category for the 3 types of Anchor guitar:

Steadfast
Homeward
Tall Ship
[weight] => 0
)

)

[page_title] =>
[shipping_type] => small_package
[shipping_address] => stdClass Object
(
)

[ups] => Array
(
[vid] => 185
[nid] => 185
[pkg_type] => 02
)

[build_mode] => 0
[readmore] => 1
[content] => Array
(
[body] => Array
(
[#value] =>

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent rutrum, tellus sed sodales elementum, urna ipsum elementum nisl, quis tincidunt nunc quam a justo. Nunc quis iaculis turpis. Quisque mollis pulvinar odio quis vulputate. Phasellus lacinia augue eget mi aliquam rhoncus.

[#weight] => 1
)

[image] => Array
(
[#value] =>

[#access] => 1
[#weight] => 1
)

[display_price] => Array
(
[#value] =>

$1,199.00

[#access] => 1
[#weight] => -1
)

[model] => Array
(
[#value] =>

SKU: aeg_tallship_01

[#access] => 0
[#weight] => 0
)

[list_price] => Array
(
[#value] =>

List Price: $1,199.00

[#access] => 0
[#weight] => 2
)

[cost] => Array
(
[#value] =>

Cost: $1,199.00

[#access] =>
[#weight] => 3
)

[sell_price] => Array
(
[#value] =>

Price: $1,199.00

[#access] => 1
[#weight] => 4
)

[weight] => Array
(
[#value] =>

Weight: 0 lb.

[#access] => 0
[#weight] => 5
)

[dimensions] => Array
(
[#value] =>

Dimensions: 0in. × 0in. × 0in.

[#access] => 0
[#weight] => 6
)

)

)

[#post] => Array
(
)

[#programmed] =>
[#tree] =>
[#parents] => Array
(
[0] => node
)

[#array_parents] => Array
(
[0] => node
)

[#weight] => 0.003
[#processed] =>
[#description] =>
[#attributes] => Array
(
)

[#required] =>
[#input] => 1
[#name] => node
[#id] => edit-node
[#defaults_loaded] => 1
[#sorted] => 1
[#title] =>
[#printed] => 1
)

[form_build_id] => Array
(
[#type] => hidden
[#value] => form-2f0745aa119a6f7c32c123d4e96f9249
[#id] => form-2f0745aa119a6f7c32c123d4e96f9249
[#name] => form_build_id
[#post] => Array
(
)

[#programmed] =>
[#tree] =>
[#parents] => Array
(
[0] => form_build_id
)

[#array_parents] => Array
(
[0] => form_build_id
)

[#weight] => 0.005
[#processed] => 1
[#description] =>
[#attributes] => Array
(
)

[#required] =>
[#input] => 1
[#process] => Array
(
[0] => form_expand_ahah
)

[#defaults_loaded] => 1
[#sorted] => 1
[#title] =>
[#printed] => 1
)

[form_token] => Array
(
[#id] => edit-uc-product-add-to-cart-form-185-form-token
[#type] => token
[#default_value] => 6b5b86507df2307bf063c52d871a0d95
[#post] => Array
(
)

[#programmed] =>
[#tree] =>
[#parents] => Array
(
[0] => form_token
)

[#array_parents] => Array
(
[0] => form_token
)

[#weight] => 0.006
[#processed] =>
[#description] =>
[#attributes] => Array
(
)

[#required] =>
[#input] => 1
[#name] => form_token
[#value] => 6b5b86507df2307bf063c52d871a0d95
[#defaults_loaded] => 1
[#sorted] => 1
[#title] =>
[#printed] => 1
)

[form_id] => Array
(
[#type] => hidden
[#value] => uc_product_add_to_cart_form_185
[#id] => edit-uc-product-add-to-cart-form-185
[#post] => Array
(
)

[#programmed] =>
[#tree] =>
[#parents] => Array
(
[0] => form_id
)

[#array_parents] => Array
(
[0] => form_id
)

[#weight] => 0.007
[#processed] => 1
[#description] =>
[#attributes] => Array
(
)

[#required] =>
[#input] => 1
[#process] => Array
(
[0] => form_expand_ahah
)

[#name] => form_id
[#defaults_loaded] => 1
[#sorted] => 1
[#title] =>
[#printed] => 1
)

[#children] =>
[#printed] => 1
)

print $form['parameters'][2]->sell_price;

Let me know if that works for you.

No...still nothing....

You can see it here...

staging.anchorguitars.com/content/tall-ship-les-paul

Thanks in advance....will be so happy to get his done and figure out what I am doing wrong!

Thanks

It looks like I can see the price listed on that page now. Did you get it figured out? If not and you still need help, go ahead and contact me through my contact form and I can help you get your issue figured out.

Thanks,

Yeah man....

Thanks for all the help....I knew I/we were on the right track...in the end....this did it...

<?php print $form['#parameters'][2]->content['display_price']['#value'] ?>

Thanks again for the help and great intro to module development.

Can you recommend any other resources to learn more on module dev?

I plan to brush up on my php first and foremost.

Thanks again

gibry21

Hi again...

I need to apply this alteration to multiple product types, not just the type product....

In my uc_alterations.module..... I tried editing this:

function uc_alterations_form_alter(&$form, &$form_state, $form_id) {
  if(stripos($form_id, 'uc_product_add_to_cart_form') === 0 && $form['#parameters'][2]->type == 'product' ) {
    $form['#theme']  = 'uc_alterations_add_to_cart';
  }
}

to this....

function uc_alterations_form_alter(&$form, &$form_state, $form_id) {
  if(stripos($form_id, 'uc_product_add_to_cart_form') === 0 && $form['#parameters'][2]->type == 'anchor_guitars' || 'anchor_merch_hoodie' || 'anchor_merch_shirts' ) {
    $form['#theme']  = 'uc_alterations_add_to_cart';
  }
}

You can see I edited....

type == 'anchor_guitars' || 'anchor_merch_hoodie' || 'anchor_merch_shirts' )

These are my 3 product classes in ubercart.

This seems to work but it causes all sorts of issue on all other forms throughout the site, basically it adds the price label etc to ALL forms.

I think it is probably a simple syntax error in my php...not sure if what I am doing with the || is correct..... it looks like its applying the alteration to ALL forms rather than just either of my 3 product types.

Any ideas?

Thanks

Ryan

Try this

if(stripos($form_id, 'uc_product_add_to_cart_form') === 0 && in_array($form['#parameters'][2]->type, array('anchor_guitars', 'anchor_merch_hoodie', 'anchor_merch_shirts'))) {
  $form['#theme']  = 'uc_alterations_add_to_cart';
}

When i put  print drupal_render($form);
it shows quantity field and add to cart button together.
Is it possible to separate quantity field and add to cart button?
i tried many variations including
 print drupal_render($form['qty']);
but unable to make it work.

thank you for your help :)

How do I allow anonymous users to view this customization. I tried implementing hook_perm but it's doesn't seem to work.

function uc_alterations_perm() {
return array(
    'administer my_custom_module' => array(
      'title' => t('Administer my_custom_module'), 
      'description' => t('Perform administration tasks for my_custom_module.'),
    ),
    'access my_custom_module' => array(
      'title' => t('Access my_custom_module'), 
      'description' => t('Access to my_custom_module.'),
    ),
  );
}

Hello,

How can I do the same thing, for a Drupal 7 / Ubercart 3 website? I need to theme the add to cart form so that I can place the attributes exactly where I need them to show up.

Thanks!

Post new comment