Order Discounts function is overriding Product Discounts?

NB - THIS POST REPLACES ANOTHER WITH THE SAME TITLE (the edit window for that one had expired, I’ve requested for it to be removed)

I’m using two functions to apply discounts according to discount config set in my CMS (this is a headless store) and held in store metadata.

  1. Product Discount function - if a discount is a ‘Buy X, get Y for Z’ or ‘Get amount off X’, this is calculated here. This works fine, even with a combination of discounts on various products, with DiscountApplicationStrategy.ALL

  2. Order Discount function - if a discount is ‘Spend X, get product Y for free’ or ‘get £ off total over X’, this is calculated here. This doesn’t work as expected, as described below:

According to the documentation, it is possible to combine product- and order-level discounts, and that order-level discounts will be calculated on the total value of the cart AFTER product discounts have been applied.

However, when I combine these discounts, the behaviour is not as expected. Take this example:

PRODUCT DISCOUNT: Product A, £5 each, buy 3 or more and save 20%

ORDER DISCOUNT: Order value (after product discounts) over £30, Product B (worth £7) is FREE by discounting £7 from the order value

Both these Product- and Order-level Discount Nodes have combinesWith set to ‘all’ (product/order/shipping)

In this case, if I have 3 or more of Product A in the cart, it discounts by 20% as expected.

BUT if I increase the quantity to 6 (ie, a total of £30 before 20% discount), then the Order discount is triggered and applied instead, and the Product discount is ignored.

THEN if I increase the quantity of product A to 7 (ie, a total of £35 before discount), it is correctly discounted to £28 BUT the Order discount is now not applied, it will only apply if I further increase the quantity of Product A to 8 (£40 discounted to £32).

The circumstances of the problematic combination (6 x Product A)

INPUT:

{
  "cart": {
    "cost": {
      "subtotalAmount": {
        "amount": "37.0"
      }
    },
    "lines": [
      {
        "merchandise": {
          "id": "gid://shopify/ProductVariant/49751193223512", <<< PRODUCT A
          ...
        },
        "quantity": 6
      },
      {
        "merchandise": {
          "id": "gid://shopify/ProductVariant/49751189422424", <<< PRODUCT B
          ...
        },
        "quantity": 1
      }
    ]
  }
}

STDOUT from Product function:

{
  "discountApplicationStrategy": "ALL",
  "discounts": [
    {
      "targets": [
        {
          "productVariant": {
            "id": "gid://shopify/ProductVariant/49751193223512" <<< PRODUCT A
          }
        }
      ],
      "value": {
        "percentage": {
          "value": 20
        }
      },
      "message": "Buy 3 or more PRODUCT A, save 20%"
    }
  ]
}

STDOUT from Order function:

{
  "discountApplicationStrategy": "MAXIMUM",
  "discounts": [
    {
      "conditions": [
        {
          "orderMinimumSubtotal": {
            "excludedVariantIds": [
              "gid://shopify/ProductVariant/49751189422424" <<< PRODUCT B
            ],
            "minimumAmount": 30,
            "targetType": "ORDER_SUBTOTAL"
          }
        }
      ],
      "targets": [
        {
          "orderSubtotal": {
            "excludedVariantIds": []
          }
        }
      ],
      "value": {
        "fixedAmount": {
          "amount": 7
        }
      },
      "message": "Spend £30 get PRODUCT B free"
    }
  ]
}

Surely this is incorrect?! It doesn’t seem to matter if I change the DiscountApplicationStrategy on the Order Discount function (Maximum or First), and in any case surely the strategies are not connected between Order discounts and Product discounts? (it’s set to ‘All’ on the Product discount function). How can the Order-level discount be apparently affecting the Product-level discount even though it’s meant to be calculated AFTER?

For clarity - this (image, below) is the state of having 8 quantity of Product A - both discounts are correctly applied.

This must be a bug? Evidently, this combination of discounts is supported - so why does it not apply in the specific circumstances described above?