I thought it would be great if you could apply a quantity condition to a promotion so if a person purchases over a certain quantity then they would receive a discount. This seemed somewhat straight forward to create but I am having a little difficulty making it work for just the one item in the cart. It will pass if any item in the cart meets the condition and not just the product selected in the Promotion Offer.

I have the condition running on commerce_order_item as the target_entity_type but can't seem to find a way to access the Promotion Offer information or promotion entity from within the promotion condition class. Is this possible? I could add a product selection field to the promotion condition form but that seems redundant since you are already having to select a product from the ProductPercentOff Offer.

Also, what if the condition is only valid for a certain offer and doesn't really work for the other promotion offers. Thoughts?

Comments

trigdog created an issue. See original summary.

steveoliver’s picture

Status: Active » Needs review
trigdog’s picture

Thanks @steveoliver. That seems to work except I am looking more for a way to check the quantity of a given order item and not the total number of items in the order. Attached is a patch that works, except it returns true for any item in the cart that matches the quantity condition.

I would like to restrict it to the product(s) selected when choosing "Percentage off each product in the order" and whatever products are listed in the product field.

Currently, it doesn't seem this is how the relationship between the promotion offer and conditions work. Let me know if I am missing something here or if you have a good idea on how to remedy approach this. It may be that I just have to create a product select field in my condition but, like I said before, it seems a bit redundant when I will just be selecting the same product as list in the promo offer product field.

bojanz’s picture

Title: Order item quantity condition for quantity discounts » Add an order quantity condition
Status: Needs review » Needs work

I have included an OrderItemQuantity condition in the new condition API committed in #2885363: Create a commerce_condition plugin type, replacing commerce_promotion_condition.

Thus #3 is unneeded, repurposing the issue for steveoliver's order-level condition.
Setting to needs work cause this will need a reroll for the new API (and a move to commerce_order/src/Plugin/Commerce/Condition)

The confusing parts of offers will be fixed in #2886641: Refactor offers.

trigdog’s picture

Great. Thank @bojanz

francois o’s picture

StatusFileSize
new2.59 KB

I had a need for order level quantity condition so came up with the attached.
Seems to work in my scenario.

s_leu’s picture

Status: Needs work » Needs review
StatusFileSize
new5.34 KB

Here's reroll including the test from steveoliver in the PR on github.

Status: Needs review » Needs work

The last submitted patch, 7: commerce_promotion-OrderItemQuantity-2875370-7.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.