Add config option to facilitate showing only one add to cart button instead of one per row

Comments

SeedTreeLLC’s picture

Dude, that was what I was going to say.

+1

larowlan’s picture

For those interested in this feature, you can do it at the theme layer by overriding theme_uc_subproduct_cart_table_form as follows:
Put this in template.php in your theme folder (create the file if not there), change YOURTHEMENAME to your theme's machine name, then flush your theme registry.
This wraps the cart button in a div with class uc-subproduct-cart-wrap so you can target it with css for position and styling.

/**
 * Custom implementation of theme_uc_subproduct_cart_table_form
 * Themes the fields as a table
 * @param $form array the form array
 * @return rendered xhtml
 * @see uc_subproduct_cart_table_form
 *
*/
function YOURTHEMENAME_uc_subproduct_cart_table_form($form) {
  drupal_add_css(drupal_get_path('module', 'uc_subproduct') .'/uc_subproduct.css');
 
  $header = $form['#display']['headers'];
  array_pop($header); //remove the cart button
 
  $rows = array();
  $col_count = count($headers);
  foreach (element_children($form['children']) as $nid) {
    $row = array();
    $node = $form['#nodes'][$nid];
    foreach ($form['#display']['columns'] as $field => $format) {
      if (in_array($field, array('cart', 'quantity', 'attributes'))) {
        //add the form field
        if ($field == 'cart') { //we don't want one on each row
          //render it so it is not done twice
          $form['children'][$nid][$field]['#prefix'] = '<div class="uc-subproduct-cart-wrap">';
          $last_button = drupal_render($form['children'][$nid][$field]);
          continue;
        }
        $row[] = array('data' => drupal_render($form['children'][$nid][$field]), 'class' => 'uc-subproduct-'. $field);
      }
      else {
        //just a static field
        if (function_exists($format) &&
        ($output = $format($field, $node))) {
          $row[] = $output;
        }
        else {
          //invalid formatter, or no value
          $row[] = '&nbsp;';
        }
      }
    }
    $rows[] = $row;
  }
 
  if (count($rows) == 0) {
    $rows[] = array(array('data' => t('There are no subproducts enabled for this node'), 'colspan' => $col_count - 1));
  }
 
  return theme('table', $header, $rows, array('class' => 'uc-subproduct-product-list')) . $last_button . drupal_render($form);
}
sfontes’s picture

thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you!!

jdln’s picture

Is there a way of having an 'add to cart' text button rather than an image? Basically I want this to look the same as the default ubercart product add to cart button.
Thanks

larowlan’s picture

Category: feature » support

Hi
Please refer to the instructions on the project page regarding changing the button.
It is a standard button that has been themed to look like an image with css.
If you remove the text indent, add the borders back, remove the background image etc etc, it will return to normal.
If you have firebug or chrome or safari with the developer tools, you can inspect the button element to see which css rules cause it to appear that way.

Lee

larowlan’s picture

Category: support » feature
boboss’s picture

@larowlan
Many many thanks

2dogrc’s picture

Thank you! Got it working very Nicely in tab for my products!
2dogrc

summit’s picture

Subscribing, greetings, Martijn

ipark88’s picture

Hello, I'm a bit of a Drupal newb, and I can't seem to get this to work. I am using acquia_prosper theme, so I went to the theme folder and changed the template.php file as stated above, and changed "YOURTHEMEMNAME" to acquia_prosper, but after saving and refreshing nothing seems to have changed. Am I doing something wrong?

larowlan’s picture

Did you flush your cache?
At the very least you need to flush the theme registry.