This is related to #1245928: Provide ability to provide Order Total and filter line item types, but we need to enrich the inline condition here as well. The basic idea is that our current "Total amount" condition should support selecting which line items should go into consideration of the "total amount." Right now it's all line items except the discount line items, so we can preserve that as a default assumption.

The solution here will be to add an optional text parameter to the commerce_order_compare_order_amount condition in commerce_discount.rules.inc. We then need to update commerce_order_compare_order_amount_build() to receive this parameter but default to it being empty. An empty value for this parameter means "all line items except order discount line items should be totaled."

Other options for the parameter should be "_all_products" => t('All product line items'); and then a list of all individual line item types. In other words, we want the person configuring this to be able to total everything, just total the product line items, or just total the line items of a given type. (Note that when evaluating the condition, if "All product line items" should be totaled, the function commerce_product_line_item_types() can be used to match a line item type against known product line item types.)

We then need to update the inline condition configuration callback in commerce_discount.inline_conditions.inc to add the parameter.

To build the options list for the inline conditions configuration form and the Rules condition, we should use commerce_line_item_options_list() but prepend to it the "_all_products" value / related label (see above).

Comments

rszrama created an issue. See original summary.

rszrama’s picture

Issue summary: View changes
joelpittet’s picture

Should all price components be included? tax, fees, vat, discount?

rszrama’s picture

Well, the idea is really line items, not price components. That makes the UI a bit more manageable here, as price components are a dime a dozen (especially when shipping modules and / or tax modules are concerned). It's the same approach used in the core Commerce issue linked above.

michfuer’s picture

Can we abstract this a bit and instead provide a list of checkboxes of line item types to include in the 'total amount'? If none are checked we include them all. Could leave the discount type off the list.

rszrama’s picture

Status: Active » Needs review
StatusFileSize
new34.98 KB

Good idea, Mike.

This was a tricky one, because we had to ensure backwards compatibility and provide a rational UI in an interface that needs some holistic healing. In the end, I was able to preserve backwards compatibility by looking at the data type (an empty value in a line item types selection will be an array while an unset value from an historical condition will be NULL), and I settled on an inline conditions UI that uses checkboxes with a more robust description. (A multi-value select list had some weird alignment issues, and trying to put a label on the checkboxes list or orient it vertically in the current scenario was a fool's errand.)

The result:

rszrama’s picture

StatusFileSize
new4.95 KB

Forgot the patch!

rszrama’s picture

Status: Needs review » Fixed

Thanks, test bot, and thanks Mike for the improvement!

  • rszrama committed a997f72 on 7.x-1.x
    Issue #2561191 by rszrama: Update the "Total amount" inline condition to...
michfuer’s picture

Looking good Ryan!

Status: Fixed » Closed (fixed)

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

fonant’s picture

I'm finding that the setting set in the Discount is not finding its way into the condition setting in the Rule.

So I uncheck "Shipping" for a "Free shipping" rule, but looking at the generated Rule it has both Product and Shipping selected still, which is wrong.

Workaround is to edit the Rule directly, to only select Product, but then I can't edit the Discount any more.