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.
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mglaman’s picture

Assigned: nvahalik » Unassigned
Status: Active » Needs review

This badboy needs to be marked CNR.

rsvelko’s picture

code 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.

joelpittet’s picture

Status: Needs review » Needs work
+++ b/commerce_discount.rules.inc
@@ -384,20 +396,49 @@ function commerce_order_has_owner_build(EntityDrupalWrapper $wrapper, $account)
+  $products_sku = preg_split('#(,|;) *#', (string) $products);

Why 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.

nvahalik’s picture

Status: Needs work » Needs review

Hi 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.

joelpittet’s picture

@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;)

Alienpruts’s picture

Wanted 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.

joelpittet’s picture

@Alienpruts yes it's specific to dev branch. Most patches are as that is where development usually happens before the next stable release.

mglaman’s picture

Status: Needs review » Needs work
+++ b/commerce_discount.rules.inc
@@ -384,20 +396,49 @@ function commerce_order_has_owner_build(EntityDrupalWrapper $wrapper, $account)
-  $products_sku = explode(', ', (string) $products);
...
+  // Split by comma or semi-colon. Allow some grace for spaces.
+  $products_sku = preg_split('#(,|;) *#', (string) $products);

I 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.

nvahalik’s picture

FileSize
4.95 KB

Okay. Patch re-rolled with latest DEV and uses the original splitting logic, which can be fixed later.

nvahalik’s picture

Status: Needs work » Needs review

Also, needs review!

mglaman’s picture

Issue tags: +commerce-sprint

Tagging for weekly sprint. Looks like a big hitter for order discount + product UX.

torgosPizza’s picture

Tested 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.

torgosPizza’s picture

Status: Needs review » Reviewed & tested by the community

Forgot 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.

joelpittet’s picture

Issue tags: +Needs tests
  1. This feature could really use some tests (my inner @alexpott) to ensure we are getting what we want.
  2. Also curious to know if it's defaulting to the existing behaviour or do we need an update hook.
joelpittet’s picture

Status: Reviewed & tested by the community » Needs work
torgosPizza’s picture

Agree, tests would be good. It's a promising start to be sure. Thanks @joelpittet!

nvahalik’s picture

Fixed 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.

nvahalik’s picture

Status: Needs work » Needs review

Worth noting that this comment was helpful for generating the code in the test. Also, needs review.

  • joelpittet committed 53d3ea2 on 7.x-1.x authored by nvahalik
    Issue #2398113 by nvahalik, joelpittet, mglaman, torgosPizza: Improve...
joelpittet’s picture

Status: Needs review » Fixed
Issue tags: -Needs tests

Committed this to -dev. Fixed a couple coding standards nitpicks on there too. elseif instead of else if Thanks @nvahalik

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

andyg5000’s picture