Hi,

I wanted to customize a shopping cart form when I saw that ubercart apply some classes for the table body columns (with some inline style !!! :/ but it's another issue). But, the table header don't have these class.

The result is that some simple design things are quite hard to do, imagine you want to center the total column. You can do it for the body, but not for the table header.

So you have to copy/paste the theme_tapir_table() function in your template.php and begin to alter it etc... etc... Very annoying for a column alignment..

I attach a very small patch, that apply the same classes to the table header than the table body.

CommentFileSizeAuthor
uc_store.patch574 byteszmove

Comments

rszrama’s picture

Status: Needs review » Needs work

Hey zmove, I think you might be working against an older version of UC. I recently reworked some TAPIr stuff so that it now sits in ubercart/uc_store/includes/tapir.inc. I imagine your patch would still apply there, but I wonder if we could also get a patch in to fix up some of the hardcoded styles. Should we also make sure we put an ID or class on the whole table based on the table ID?

zmove’s picture

Hi Ryan, thanks for a so quick answer.

Hmm, strange I work on the latest dev version found on drupal.org. I didn't delete ubercart folder before installing the new one, maybe this is the cause.

For the patch I provided, I didn't see it immediately, but it bring a problem on the user order page. The title of the table show "array".

This is caused because my patch use 2 different key 'data' and 'class' for the table generation, so, each call of tables header have to be modified to understand 'data' and 'class' key I imagine...

For the way to generate a pretty perfect table for designer, the best is to look how views module do, because it do it very well.

This mean an id for the table, an 'odd' and 'even' class for the rows, an unique class name for each column (thead column too!) and a 'first' class to add to the first row and column and a 'last' class for the last ones. This results something like that:

<table id="my_unique_id">
 <thead>
  <tr class="odd first last">
   <th class="col1 first">Column 1</th>
   <th class="col2">Column 2</th>
   <th class="col3 last">Column 3</th>
  </tr>
 </thead>
 <tbody>
  <tr class="even first">
   <td class="col1 first">Content 1.1</td>
   <td class="col2">Content 1.2</td>
   <td class="col3 last">Content 1.3</td>
  </tr>
  <tr class="odd">
   <td class="col1 first">Content 2.1</td>
   <td class="col2">Content 2.2</td>
   <td class="col3 last">Content 2.3</td>
  </tr>
  <tr class="even last">
   <td class="col1 first">Content 3.1</td>
   <td class="col2">Content 3.2</td>
   <td class="col3 last">Content 3.3</td>
  </tr>
 </tbody>
</table>
mbelos’s picture

After a ton of research, I've worked out a way to do this using Ubercart 6.x-2.2 (on the cart page at this stage - the checkout page will follow):

/**
 * Implementation of hook_form_alter().
 */
function MODULENAME_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'uc_cart_view_form') {
    $form['items']['#columns']['desc']['cell'] = array('data' => 'Resources', 'class' => 'desc');
    $form['items']['#columns']['remove']['cell'] = array('data' => $form['items']['#columns']['remove']['cell'], 'class' => 'remove');
    $form['items']['#columns']['total']['cell'] = array('data' => $form['items']['#columns']['total']['cell'], 'class' => 'total');
  }
}
timdiacon’s picture

I have been trying to find a way of doing this myself - mbelos can you tell me where would I need to place your form alter hook?

mbelos’s picture

Sorry I don't log into Drupal enough to check issues, etc - if anyone is stuck on this, it needs to be placed in a module, so create your own module and put it in there.

timdiacon’s picture

Sorry I haven't ventured into creating my own modules yet. Any chance of uploading this as a module?

tr’s picture

Status: Needs work » Closed (won't fix)

As of Ubercart 2.x, Ubercart uses the core Drupal function theme_table() to generate table markup. Thus, Ubercart tables receive all the "standard" classes like even/odd that are inserted into all Drupal tables. Because Ubercart relies on the core Drupal function, I think that for the most part any changes or improvements to the table theming should be made as patches to that core function. Specifically the per-column classes: If these are important for themers, then it's something that should be made part of theme_table() so that *all* modules will benefit. I don't see the point in taking a step backwards and having Ubercart ignore the core functions and generate all the markup with Ubercart-specific functions.

Josephnewyork’s picture

Worked like a charm. Thanks mbelos. I rewrote it more dynamically if anyone else needs it:

function <module>_form_alter( &$form, $form_state, $form_id ) {
  if ($form_id == 'uc_cart_view_form') {
	  foreach($form['items']['#columns'] as $field=>&$data) {
		  $data['cell'] = array('data' => $data['cell'], 'class' => $field);
	  }
  }
}