I - and others - would like to see that hook_cart_display() will be invoked for all modules and not just for those that provide a product type.

Comments

xano’s picture

Version: 5.x-1.2 » 5.x-1.3-rc1
Island Usurper’s picture

Status: Active » Closed (won't fix)

I don't think this is something that will happen any time soon. Sorry.

xano’s picture

Version: 5.x-1.3-rc1 » 6.x-2.x-dev
Status: Closed (won't fix) » Active
rszrama’s picture

Status: Active » Postponed

Would need a good rationale for this for it to be considered for UC 3.x. Please don't move it from postponed if you add any info.

xano’s picture

Well, there's a simple reason for allowing all modules to intercept the cart display: why prevent it? Don't put limitations on your software unless it's necessary. There are dozens of maintainers that would like their contribs to modify the cart display to add or alter features, but because those modules don't offer a product type themselves this is impossible.

Island Usurper’s picture

Status: Postponed » Closed (works as designed)

hook_cart_display() is called for each item in the cart, and each particular item's module gets to decide what it looks like in the cart. It's really more of a callback with a standardized name than a hook that's used with module_invoke_all(). This is the way the node hooks like hook_view() and hook_insert() work. Only modules that have a node type (defined in hook_node_info()) actually implement hook_insert(), but if any other module wants to modify what gets inserted, it needs to use hook_nodeapi('insert').

You can change how the cart looks from any module already with hook_form_alter(), since all the data is put into the form building function. Take a look at the TAPIr documentation, since that's heavily involved in the construction of the form.

I don't want to change the fact that only products can be added to the cart. That lets Ubercart assume that data like price, sku, etc. are available to use. That's what I thought you were asking for at first, which is why reacted so strongly. Changing the way the cart looks after hook_cart_display() is used is the way to go.

ckidow’s picture

A tip I've got from "longwave" in irc:

"You can try setting $item->module in hook_cart_item op 'load' to your own module name, then your custom hook_cart_display might get called".

And it just worked.

Big THX to the Drupal Community!

joachim’s picture

Title: Invoke hook_cart_display() for all modules » clarify use of hook_cart_display()
Category: feature » bug
Status: Closed (works as designed) » Active

> It's really more of a callback with a standardized name than a hook that's used with module_invoke_all().

That's fair enough.

But the documentation does not make this clear and should be changed.

http://api.ubercart.org/api/function/hook_cart_display/2

Description

Control the display of an item in the cart.

Product type modules allow the creation of nodes that can be added to the cart. The cart determines how they are displayed through this hook. This is especially important for product kits, because it may be displayed as a single unit in the cart even though it is represented as several items.
rszrama’s picture

Title: clarify use of hook_cart_display() » Clarify use of hook_cart_display()
Component: Code » Documentation
Category: bug » task
Island Usurper’s picture

Title: Clarify use of hook_cart_display() » clarify use of hook_cart_display()
Category: task » bug

And just so we don't forget, http://www.ubercart.org/docs/api/hook_cart_display should also be updated.

Island Usurper’s picture

Title: clarify use of hook_cart_display() » Clarify use of hook_cart_display()
Category: bug » task

Szrama!!!!

rszrama’s picture

MantooooOOOOooooth!!! >: )

Pierco’s picture

If you want to alter the cart display, use hook_tapir_table_alter() and check $table_id = "uc_cart_view_table":
http://api.ubercart.org/api/function/hook_tapir_table_alter/2

function mymodule_tapir_table_alter(&$table, $table_id) {
  if($table_id == 'uc_cart_view_table') {
    foreach($table as $k => $v) {
      if(is_array($v) && isset($v['nid'])) {
        $item = node_load($v['nid']['#value']);
        $table[$k]['mycolumn'] = array(
          '#value' => 'my value',
          '#cell_attributes' => array('class' => 'myclass'),
        );
      }
    }
    $table['#columns']['mycolumn'] = array(
      'cell' => 'My Title',
      'weight' => '3',
    );
  }
}
japanitrat’s picture

I don't think this is something that will happen any time soon. Sorry.

why is that? It's a fairly minimal change in code, just replace the module_invoke with module_invoke_all?

Edit: nevermind, just read the whole thread --

longwave’s picture

Status: Active » Fixed

At long last, improved in both branches by adding two lines to the API documentation. Also changed the reference from "checkbox" to "submit" in the same docs, since we switched the method of removing items from the cart.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.