hook_cart_item breaking cart product removal?

Posts: 7
Joined: 08/07/2008

I am making some changes to the uc_affiliate module (Drupal 5 setup with latest Ubercart) and I've noticed that when the module is enabled, I can't remove from cart the products I added.

Little digging showed me why:
Using hook_cart_item we add the affiliate field to the data array, so we get $item->data['affiliate'].

Hook_cart_item is not called when adding products to the cart, so it doesn't get saved in data (uc_cart_products table), but when the product is to be removed from the cart (cart update), the whole data (with the affiliate field) is passed to uc_cart_remove_item() in uc_cart, so the removal fails (uc_cart_remove_item uses a SQL query that compairs the passed in $data and the one in the DB. One has the affiliate field, the other doesn't).

Should it be this way (am I missing something), or is this a bug?
How to avoid this, should I say: unpleasant, behaviour?

Thanks!

Posts: 5353
Joined: 08/07/2007
AdministratorHead Code Monkey - I eat bugs.

I believe your answer lies within hook_add_to_cart_data(). You can find an example in uc_attribute.module.