Because product discount rules fire on the commerce_product_calculate_sell_price event, but order discount rules fire on the commerce_discount_order event, order discounts can never be evaluated before product discounts, even if their sort order is lower.
For example, if you have an order discount and a product discount, both of which are not compatible with any other discounts, the product discount will always "win" and be applied first, even if you set the order discount's sort order lower than the product discount's.
One way I can think of resolving this issue would be to determine which discounts should be applied to an order before actually applying them. Each discount would have two rules, one to determine if the discount should be applied to the order and one to actually apply the discount if necessary. That way, the actual "apply" rules can still fire where they do now so that taxes and other sell price calculation works work properly with them.
The process would look something like:
commerce_cart_order_refreshfires.- An event fires that determines which discounts should be applied to the order, based on their compatibility and any other conditions imposed on the rule. This compatibility would have to be stored somewhere. Perhaps an arbitrary array on the order that's never saved to the DB?
- The
commerce_product_calculate_sell_priceevent fires for each line item. All product discount rules check to see if they're compatible with the order (using information stored in step #2) and apply themselves if necessary. - The
commerce_cart_order_refreshhook fires, which in turn causes thecommerce_discount_orderevent to fire. All order discount rules check to see if they're compatible with the order (again using info stored from step #2) and apply themselves if necessary.
Comments
Comment #2
Scott Robertson commented