Prevent adding product to cart based on date comparison

I'm building a conference web site and as part of the site, we offer various paid courses that are happening simultaneously and I don't want the user to be able to add an event (product) to their cart if they already have added a product to the cart that's occurring at the same time. I've created a start date field for which to compare this information but problem is I'm not sure of the best way to build this functionality. I'd like to disable the add to cart button using the Calculate Sell Price event.

Any advice is greatly appreciated.


Posted: Oct 31, 2014


joshmiller Josh Miller on November 11, 2014

Commerce Stock (https://drupal.org/project/commerce_stock has a quagmire of a way to disable the cart. But I think it would be reproducible.

Once installed, you can see a rule action that is used to "disable" a cart.

If you wanted to do it the "right way" then you would create a stock module that implements stock based on a user's cart contents.

But I think it would be possible to create a rule that:

1. Sets a data variable to false.
2. Creates a loop on current user's order line items
3. Inside that loop runs a rule component that returns true if a product matches your requirements
4. Sets that original data variable to the output of the last action
5. Outside that loop run a final conditional component that disables the cart if the original data variable is true.

Would need testing, but it *should* work (tm).