I'm trying to add a product to the cart programatically.

As far as I can tell, uc_cart_add_item() is the correct way to do it. It in turns invokes hook_add_to_cart and modules may agree or disagree with the adding of the item to the cart.

However, the caller gets nothing back about this, and so has no idea whatsoever whether the operation has succeeded or not.

The obvious kludge of calling hook_add_to_cart() myself isn't even viable, as the documentation for that says "This hook may also be used simply to perform some routine action when products are added to the cart." -- hence calling it twice could lead to actions being performed twice.

Comments

longwave’s picture

Version: 6.x-2.x-dev » 7.x-3.x-dev
Category: bug » feature
Status: Active » Postponed

The API for uc_cart_add_item() sucks, but I don't see how we can change this without breaking backward compatibility, so unfortunately we have to postpone this for now.