It's a shop where you can buy drinks. For every bottle/can there has to be an extra item with bottle/can deposit visible to the user.

So for this I added the cans and the deposit as single items. Every can has 3 attributes for the packaging unit of the tray: 6x250ml (default), 12x250ml, 24x250ml.

After that I added a product kit with 1x "can tray 6x250ml" and 6x deposit. This works fine. But if the user selects 1x "12x250ml" the deposit will just calculates the normal 6x.

Now I thought about manipulating the cart before it is visible to the user. For example: Take the quantity of the item, calculate the deposit by the checked packaging unit and multiply by the item quantity. The calculation is pretty simple.

What function/hook can I use to do this?

I tried to deal with hook_uc_cart_item_presave($entity) but it seems, that the function gets triggered once for every product in the product kit. I can't find a solution to check the quantity on the main item as well as the checked attribute and then pass it to the second run for the deposit item.

1 Answer 1


It seems that - against the official docs of ubercart - the hook hook_uc_cart_alter IS available for Drupal 7.

Found the answer here on Drupal Answers in an old question: https://drupal.stackexchange.com/a/94497/53491

With the available $items-object I iterate through my cart as I need it. Works perfect.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.