I'm trying to set up a Rule that will fire whenever a certain product is bought. I've been able to do this using "Order contains a particular product" which then asks for the SKU, but we'll be adding more of these products in the future (they are event registrations, by the way).
Rather than having to edit/add another rule each time a new event registration is added and adding the SKU to the condition, is it possible to have the condition reference the product type (event registration) instead of a specific SKU?
I've tried doing this by adding the condition "Entity has field" and referencing a field that is only in the event registration product type, but it doesn't seem to work. Any ideas?
| Comment | File | Size | Author |
|---|---|---|---|
| #11 | 1291564-1-rules-product-type-condition.patch | 3.38 KB | farald |
Comments
Comment #1
rszrama commentedYou can't do this with the basic rule, but you can either use a custom action or try your hand at a loop in your rule's actions that iterates over the commerce-order:commerce-line-items and calls a component that can perform an action based on the referenced product's type. I don't think we'll be adding any custom conditions at this point in time for this unless it becomes a more common feature request. I'll keep my eye out. If this functionality doesn't need to be configurable via the UI, there's nothing wrong with implementing hook_commerce_checkout_complete() in a custom module for the site to perform your additional business logic.
Comment #2
skyredwangI also think adding a "Order contains a particular product type" rule condition is useful. I am re-opening this issue, and if I have the time, I will write a patch.
Comment #3
rszrama commentedSounds good. Nice to meet you in Denver!
Comment #4
sreynen commentedI think this might already be covered here:
http://drupal.org/node/1331230
I didn't end up needing this, so didn't try it, but it looks good.
Comment #5
rszrama commentedYeah, I saw that module in a training yesterday, but I think it'd still be good to have as a core feature. I'll just remember to coordinate with them once it works in core so they can remove it from that package at the same time.
Comment #6
skyredwangyeah, I also think it should go into the core instead of in a contrib
Comment #7
Yaazkal commentedHello, reopening this issue just to give my +1 on this feature request, as in comment No. 2 it is very useful to have a "Order contains a particular product type" rule condition.
Thanks !
Comment #8
sonictruth commentedI found myself wanting this feature today so +1 for me.
Comment #9
derekw commentedI don't know how to create a patch but I think I pulled this off by copying/modifying the SKU functions. My first try so please be gentle. This seems to work for me.
At line 95 added condition commerce_order_contains_product_type
Then at line 302 Added function commerce_order_rules_contains_product_type:
Comment #10
tuccio commentedHow about using taxonomy and http://drupal.org/project/commerce_conditions
Comment #11
farald commentedHere's a patch for the code in #9.
Comment #12
farald commentedComment #13
kenorb commentedComment #14
chris matthews commentedThe 6 year old patch in #11 to commerce_order.rules.inc applied cleanly to the latest commerce 7.x-1.x-dev and (if still relevant) needs to be reviewed.