4 replies [Last post]
quaoar's picture
Offline
Bug FinderEarly adopter... addicted to alphas.Getting busy with the Ubercode.Not Kulvik
Joined: 08/08/2007
Juice: 179
Was this information Helpful?

There is a hook called hook_cart_item.
If I want to add a small piece of information to the text for every item in the cart, I can (or not) do this:

function hook_cart_item($op, $item) {
    if($op == 'load') {
        $n = node_load($item->nid);
        $item->title = $item->title.' (blah blah)';
    }
}

This will show "node title (blah blah)" in the cart block, but not in the cart view or checkout. Because the default implementation for hook_cart_display loads the node and uses its node title, instead of the supplied $item and its $item->title.
Part of uc_product_cart_display:

function uc_product_cart_display($item) {
  $node = node_load($item->nid);
  $element['title'] = array(
    '#value' => l($node->title, 'node/'. $node->nid),
  );
  return $element;
}

Any special reason for this?
$item->title is always updated whenever the cart is displayed. So the item->title will -always- be equal to $node->title, as long as no one have used hook_cart_item in the hope that it would actually change something.

I've changed it to this, in our code base:

  $element['title'] = array(
    '#value' => l($item->title, 'node/'. $node->nid),
  );

Erlend Strømsvik
Ny Media AS
erlend@nymedia.no

Lyle's picture
Offline
AdministratoreLiTe!
Joined: 08/07/2007
Juice: 6846
Re: Bug? A bit strange use of node title in uc_product_cart_disp

Must have not been thinking too hard that day. Makes perfect sense to use the $item->title there.

j0rd's picture
Offline
Getting busy with the Ubercode.
Joined: 07/16/2008
Juice: 453
Using this feature/bux fix myself....but....

How do I change the link away from "node/" . $node->nid

I need to change the link because I do not want people to change the actual item...i have another node that's created/edited to create the information for the order (which allows users to upload their own photo). So I would like to change this link, to edit that particular node and not the product.

Reason for this:
http://www.ubercart.org/forum/support/2626/q_how_allow_users_upload_busi...

I'm planning to do this by using uc_product_cart_display ... but it appears this isn't a normal hook that I can get into. Any advice on how one can change the product link?

Lyle's picture
Offline
AdministratoreLiTe!
Joined: 08/07/2007
Juice: 6846
Re: Using this feature/bux fix myself....but....

hook_form_alter() can be used on 'uc_cart_view_form' to change any part of the cart table. It's become a fairly common task for some modules, that we'll probably redo the way that page is generated at some point.

j0rd's picture
Offline
Getting busy with the Ubercode.
Joined: 07/16/2008
Juice: 453
Re: Re: Using this feature/bux fix myself....but....

Thanks for the help. I eventually found out I could do it like that (rather than overriding $item->module which caused all sorts of fun issues).

I agree there should be better hooks into that function.