This module is very close to what I'm looking for, but my business logic is a fraction different. Rather than applying the coupon when any one of the referenced products is in the cart, I need the coupon to only apply when all of the referenced products are in the cart. Can you suggest a way to achieve this? (e.g. does it require a whole new condition instead of list_contains_item?)

Comments

AndyF’s picture

Hi,

There's a couple of ways that might work I think. Without coding you could try:

  1. Create a rule on validating a coupon that checks for the reference field on the coupon, and if found it loops through the referenced products, firing off a rule component with the coupon and the product.
  2. The rule component checks if the product is referenced by the coupon, and if not invalidates the coupon.

Alternatively with coding you could create a new condition, something like Order contains all products referenced by the coupon. You'd then just use that instead of Order contains a product that is referenced by the coupon in Coupon Validation: Check the referenced products.

If you took the latter approach, I'd happily add the new condition to the module.

HTH

jonathan_hunt’s picture

Thanks for the response. I've experimented with this and AFAICT any solution that relies on Validate a coupon is flawed because it only occurs when the coupon is first applied. If I apply a coupon and subsequently alter the cart (i.e. remove a referenced product) the coupon still applies to the remaining product.

I started writing a new condition "commerce_couponprodref_order_has_all_referenced_products". I thought I could add it as a condition in the rule "Apply percentage coupons to referenced product line item" but although I can reference the Order in the conditions, I can't seem to select the Coupon as an entity in the Data selector...

AndyF’s picture

AFAICT any solution that relies on Validate a coupon is flawed because it only occurs when the coupon is first applied

Ah, didn't know that! What exactly are you looking for: do you want the coupon removed from the order as soon as a key product is removed? I think that could be done with Rules by using the event after removing a product from cart and effectively doing the validation again at this point.

although I can reference the Order in the conditions, I can't seem to select the Coupon as an entity in the Data selector

I haven't taken a look as I'm a bit snowed under :/ but have you used an entity has field condition to bring the coupon into scope?

AndyF’s picture

Status: Active » Closed (works as designed)