We evaluate Order item conditions order item by order item. So if you create a "Product category: Hats" and "Product quantity: 2" condition, it will only match order items that have a hat product and a quantity over 2. If you have two Hat order items with quantity 1 each, that won't trigger the promotion.

We need to invent a way for the order_item_quantity condition to get all matched order items, to be able to add up and compare their quantities. Not sure what's cleanest yet. We want conditions to be independent of the parent entity, so we can't just pass the promotion. We could invent a fake condition entity_type, but that's kinda dirty. We could invent a way for conditions to request a second param to evaluate(). Remains to be seen.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

bojanz created an issue. See original summary.

bojanz’s picture

Issue summary: View changes

Expanding with possible solutions.

bojanz’s picture

  • bojanz committed 14ce9da on 8.x-2.x
    Issue #2893367 by bojanz: The Product: Quantity condition doesn't take...
bojanz’s picture

The offer conditions issue needs order_item_quantity to become a commerce_order condition.

So I've pushed the first part of the fix. It makes the condition operate on an order, and updates the tests.
The second half will land with the two issues in #3.
This means that we're temporarily introducing a regression, but only for about 12h while I commit the other pieces.

bojanz’s picture

Status: Postponed » Needs work

Both issues from #3 have landed, time to wrap this up.

bojanz’s picture

Status: Needs work » Needs review
FileSize
5.56 KB

Moved the condition from commerce_order to commerce_promotion, since it's now promotion specific.
Added the new logic with tests.

Still waiting on feedback for the UI (whether we need help text to indicate what's going on).

MegaChriz’s picture

@bojanz
Thanks for all your work on discounts lately, I hope I can give some feedback on the UI in the next few days.

Status: Needs review » Needs work

The last submitted patch, 7: 2893367-7-total-quantity.patch, failed testing. View results

bojanz’s picture

Status: Needs work » Needs review
FileSize
9.19 KB

Fixed test fails, renamed the condition to "Total discounted product quantity", sent it back to the "Products" group. It's not ideal, but we're out of time.

  • bojanz committed 9715844 on 8.x-2.x
    Issue #2893367 by bojanz: The Product: Quantity condition doesn't take...
bojanz’s picture

Status: Needs review » Fixed

Committed.

MegaChriz’s picture

FileSize
70.18 KB
56.11 KB

UI feedback

Here is some feedback on the UI. I haven't looked at the promotions UI lately, so forgive me if the particular UI I'm commenting on does not belong to this issue.

Tested with custom conditions

I've had two custom order item conditions and after the update to the latest dev I noticed that these moved from "Product Restricted" to "Offer" when using the offer type "Fixed amount off each matching product" (I saw later that on the Commerce Slack channel that there was a change record, so these condition plugins probably need to be updated).

This is how it looked before:

This is how it looks now:

(both conditions are available as patches in #2971381: Add a product SKU condition and #2938731: Order total range condition)

Condition in "Offer" section are additive

It took me a while to notice that the conditions in the "Offer" section are additive instead of restrictive. With the conditions set in the image above, the discount applies to a product whose "SKU" is "e1556", but also to any other product with a quantity of 3. That was a thing that wasn't immediately obvious to me. I realize that part of that confusion is probably because the "Limit by quantity range" doesn't belong there and should instead appear in "Product Restrictive" where it was before.
Nonetheless I think it would be a good idea to emphasize that when using multiple conditions in the "Offer" section, things add up.

Status: Fixed » Closed (fixed)

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