Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Currently the Product(s) inline condition/rule checks to see if the order contains all of the products listed in the rule. So if you want to see if an order contains one of 10 products, you have to have an OR condition and then add 10 individual "order contains product" conditions. This patch adds an operator that would allow you to choose from the following options:
- all (inclusive all) (the default) makes sure that the order contains all of the listed products. The order can contain other products.
- any (inclusive any) will apply if the order contains any the products listed. This order can contain other products.
- exactly (exclusive all) matches if only listed products are on the order and all of them are on the order. The order cannot contain any other products.
- only any (exclusive any) matches if any of the products listed are on the order. The order cannot contain any other products.
Negating any would also give you a none option.
Assume that SKUs "C", "E", and "F" are in the condition list.
SKUs in Cart | Any | All | Exactly | Only Any | None (!Any) | Description | ||||
---|---|---|---|---|---|---|---|---|---|---|
B | C | D | E | F | True | True | False | False | False | All of the SKUs in the list, but not only SKUs. |
B | C | True | False | False | False | False | Any of the SKUs in the list. | |||
B | D | False | False | False | False | True | None of the SKUs are in the list. | |||
C | E | F | True | True | True | True | False | Every SKU in the list, only SKUs in the list. | ||
E | F | True | False | False | True | False | Only SKUs in the list, but not every one. |
Comment | File | Size | Author |
---|---|---|---|
#17 | 2398113-17-interdiff.txt | 5.17 KB | nvahalik |
#17 | 2398113-17-improve_order_discount_products_inline.patch | 9.37 KB | nvahalik |
Comments
Comment #1
mglamanThis badboy needs to be marked CNR.
Comment #2
rsvelko CreditAttribution: rsvelko commentedcode looks ok, when I read it.
Somebody else should read it too. And we should test it after being applied if all the logic works indeed AND 2. if changing the rule definition would NOT break existing user sites.
Comment #3
joelpittetWhy does semi-colons need to be an option? Maybe we can keep it simple with just commas but the space graces sounds like a much better plan.
Comment #4
nvahalik CreditAttribution: nvahalik commentedHi joelpittet, do you have a particular reason why they shouldn't be an option?
Having commas and semi-colons makes it a bit easer for some folks because semicolons are common separators for lists in the online world. My intention for including it is primarily to keep things simple for the users who may forget or copy and paste from other solutions: including CSV files and spreadsheets.
Comment #5
joelpittet@nvahalik I'm saying that because there is no precedent for semi-colons. It adds unnecessary complexity that needs to be supported for the minimum viable code for the feature which likely could inhibit a committer from accepting the patch. And there is no documentation that that is an option to use semi-colons in the help so it's a hidden feature that if accidently dropped could make the users peeved. Why not pipe symbols| too, or ~ or *... too easy to also bikeshed;)
Comment #6
Alienpruts CreditAttribution: Alienpruts commentedWanted to try this out, but for the life of me I (and patch command) can't locate commerce_discount.inline_conditions.inc file. Is this specific to dev branch?
Tried looking for it there though, also no sign of it.
Comment #7
joelpittet@Alienpruts yes it's specific to dev branch. Most patches are as that is where development usually happens before the next stable release.
Comment #8
mglamanI think this should stay AS IS, as it's outside of the issue's scope.
100% for opening a new issue to add new separator items. But that way we keep the patch to just logic operators, not how it find SKUs.
Comment #9
nvahalik CreditAttribution: nvahalik commentedOkay. Patch re-rolled with latest DEV and uses the original splitting logic, which can be fixed later.
Comment #10
nvahalik CreditAttribution: nvahalik commentedAlso, needs review!
Comment #11
mglamanTagging for weekly sprint. Looks like a big hitter for order discount + product UX.
Comment #12
torgosPizzaTested the patch and it's working beautifully for me. In fact it may help solve the issues we were having with product-level discounts disappearing, because (at least referring to the proposal at #2621680: Remove Product Display discounts and only use order discounts for 1.2), product discounts tend to cause issues such as discounts disappearing from checkouts, and to combat that, I changed a discount to be order-level. This patch helps facilitate a much simpler (and better!) means of creating product conditions on an order-level discount. It's more robust as a result and I think it makes sense to commit this.
I'll set this to RTBC for now, but I haven't given it a totally thorough review yet; I can only speak for our own experience. But so far this patch is very promising! Others may want to give this patch a deeper review.
Comment #13
torgosPizzaForgot to set RTBC, but as I mentioned further review by others (especially anyone currently having problems with product-level discounts) should take it for a spin.
Comment #14
joelpittetComment #15
joelpittetComment #16
torgosPizzaAgree, tests would be good. It's a promising start to be sure. Thanks @joelpittet!
Comment #17
nvahalik CreditAttribution: nvahalik commentedFixed a whitespace issue (there are more but that's a different issue).
Added test. Essentially, I added a new test class for conditions with the idea that other inline conditions could add tests to that suite. Or not. It's whatever.
Comment #18
nvahalik CreditAttribution: nvahalik commentedWorth noting that this comment was helpful for generating the code in the test. Also, needs review.
Comment #20
joelpittetCommitted this to -dev. Fixed a couple coding standards nitpicks on there too.
elseif
instead ofelse if
Thanks @nvahalikComment #22
andyg5000This make bug #2655084: Improperly implemented rules options list :(