Maybe it is a very specific use case, but I want to use the condition "Order contains specific products", but add extra requirements concerning quantity. So you can define that for example a payment option or shipment option is only available for a specific product, and only for a specific quantity. So three fields are added:
- operator (<, <=, ==, >=, >)
- quantity
- hide if other products are added

(This last option you can use for example: provide a payment option free shipping, that is only available for specific products, and is not available if other products are added to the basket.)

I can understand if this is rejected, but I thought to throw the patch out here so if someone needs it, it is available.

The extra option will alter the original behavior, they are supplemental.

I have not modified the tests to check this behavior.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

JoshaHubbers created an issue. See original summary.

JoshaHubbers’s picture

JoshaHubbers’s picture

Hm, even more rare maybe... I also added the option to evaluate to FALSE if other products besides the selected product are ordered.

JoshaHubbers’s picture

Issue summary: View changes
JoshaHubbers’s picture

A new patch. This patch adds an operator options. So you can choose not only a max quantity, but can also choose other operators (<, <=, ==, >=, >).

JoshaHubbers’s picture

Issue summary: View changes
JoshaHubbers’s picture

Hm, added default setting for the form elements so they don't throw errors if not used.

The last submitted patch, 5: commerce-specific_product_max_quantity_condition-3098889-5.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

Status: Needs review » Needs work

The last submitted patch, 7: commerce-specific_product_max_quantity_condition-3098889-7.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

4kant’s picture

Hi Joshua,
your patch helps me for my usecase - a promotion.

Customers should get a gratuated discount in kind:

  1. buy 10 - get one extra
  2. buy 20 - get 3 extra
  3. buy 30 - get 6 extra

The extra items should be listed in the cart, like "normal" purchased items with price 0,- €.

Unfortunately the 3 discount rules overlaped (20 items triggered rule 10 two times + rule 20) - and that gave me a buggy price (e.g. one third of the original price).

With your patch it is possible to trigger the rules distinctly and threrefore get the price as expected.

  • drupal core: 9.4.5
  • commerce core: 8.x-2.31

The patch applied cleanly.

It would be very good to have the same condition to the product variation.

Thanks!
Wiegand