I have one certain product that needs to be in the cart under certain circumstances. I have been looking at the Ubercart api documentation and I don't see any hooks that would be the obvious place to see if a certain item exists prior to checkout.
I could use the hook_add_to_cart hook to add the special item whenever the first item is added, but I'm concerned that the visitor may remove the item and then complete the purchase without the required item.
Any suggestions how to make sure the special item is in the cart on checkout?
You can have a module and run something like:
function mymodule_init() {
if (preg_match('/checkout/', request_uri()) {
$items = uc_cart_get_contents();
foreach ($items as $item) {
// code
}
}
}
That will fire up on the checkout page, and fetch the cart contents. Everytime they hit the checkout page, uc_cart_get_contents() returns the cart contents.
http://www.ubercart.org/docs/api/uc_cart_get_contents
There are probably better ways to do what you want to do though, like using a Conditional Action to prevent checkout if Item B is in the cart but Item A is not. You can also look at Product Kits, but I don't have much experience with that.
From what you have said it sounds as though the product kit module might be very much worth looking into as a way of ensuring any items associated with the main product are kept in the cart.
Product kit comes as part of ubercart and you will find it on the modules page under 'Ubercart - extra'. If this is no good then we can see about using the API :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With