3 replies [Last post]
hinrichsislcocom's picture
Offline
Bug Finder
Joined: 05/28/2008
Juice: 92
Was this information Helpful?

Hello,

It looks as though the table_alter hook has been removed from the tapir functionality in the current D6 version of ubercart. Is there another method being introduced for changing the product listing table, or is this functionality yet to be implemented in a future release?

Specifically, I have no use for the 'list price' column and I simply want to remove it.

I played a bit with pasting the old tapir_invoke_all function and merging it into the header array using line:
$table['columns'] = array_merge(uc_product_table_header(), tapir_invoke_all('table_alter', 'product_table', 'fields', $arg));
...but it looks like maybe this needs a more involved solution.

thanks!

Bob Hinrichs
ISL Consulting
http://www.islco.com

Ryan's picture
Offline
Joined: 08/07/2007
Juice: 15438
Re: 6.x-2.x-dev: table_alter not hooking

I believe we switched it to just use hook_form_alter() for now, which I don't really like. Check it out for now, and we'll see if TAPIr stays the same moving forward. Might be we get to a point where we hard code all the tables but expose the table data to Views for folks that want to alter them... who knows.

hinrichsislcocom's picture
Offline
Bug Finder
Joined: 05/28/2008
Juice: 92
new solution

Thanks Ryan, using form_alter seemed to only give me access to the two 'buy_now' elements on the product listing, not the whole table. It seems the table wraps around the two rendered forms, so form_alter doesn't affect the table.

But this led me to see that tapir_table is a theme used to render the table, and is passed the entire array. It works to override the tapir_table theme, which works just fine.

function [my_module]_tapir_table($form){
if ($form['#attributes']['class']=='category-products'){
foreach($form['#value']['columns'] as $key=>$column){
if ($column['id']=='list_price'){
unset($form['#value']['columns'][$key]);
}
}
}

return theme_tapir_table($form);
}

I think it would work better if the the array keys were column id values (like menu), if that is possible. Also since there is no table (or form) id, I am using what I see to be the next best thing, the class name. You could perhaps use a var reference to avoid having to call the main theme function at the end. In the end, this works similar to a table_alter.

Maybe a s a future addition, the table parameter could "pass through" a table_alter hook before going to the tapir_table theme, if it would be nice to provide continuity with the old version, and perhaps a method that is a little more clear to discover.

Bob Hinrichs
ISL Consulting
http://www.islco.com

Ryan's picture
Offline
Joined: 08/07/2007
Juice: 15438
Re: new solution

Forgot to get back to this thread! So, I actually came to the same conclusion about the same time and updated the core tables to use the ID as the key for elements in the columns array. You can now alter them as expected through hook_form_alter(). Check out the announcement and docs through this thread:

http://www.ubercart.org/forum/announcements/7516/updated_tapir_tables_ap...