Error in Shopify function product discount combinations

Hello,

We have recently observed a peculiar pattern of discount combinations in the Shopify Checkout. We have an automatic discount set up using Shopify Function, targeting three variants - for instance, X, Y, and Z, with a 28% discount with the total value of about $39, which is distributed across the items in the bundle. Additionally, we have another product discount set at 20%, also configured through Shopify. Some of the products within the bundle are eligible for this discount as well, specifically, X and Y in the example given. When we apply the Shopify discounts on the checkout page, Shopify first applies the total bundle discount of 28% with a value of $39 to the Z product, and then applies the Shopify discount to the other products in the cart.

This outcome is not as expected. We anticipated that the bundle discount would remain applicable to X and Y because it is greater than the Shopify automatic discount (28% > 20%). However, it appears that Shopify’s algorithm is attempting to optimize the overall cart price, whereas, in the past, Shopify aimed to optimize the final price of each line item, not the total cart price. I mean here we anticipate the bundle discount to remain after inserting the Shopify automatic discount because for each line item, the bundle discount is larger than the Shopify Automatic discount.

Do you have any suggestions on how to resolve this issue and prevent the total bundle discount from being applied to one of the products within the bundle?

Do you have any code we can look at to see? Maybe there is a way, but without knowing how you are applying the discounts precisely I cannot help in this situation.

this is the function result, my product discount function is an ordinary one that just gives a discount for some variants.

{
        discounts: [
            {
                targets: [
                    {
                        productVariant: {
                            id: 'gid://shopify/ProductVariant/Y',
                            quantity: 1
                        }
                    },
                    {
                        productVariant: {
                            id: 'gid://shopify/ProductVariant/X',
                            quantity: 1
                        }
                    }
                ],
                value: {
                    fixedAmount: {
                        amount: 20,
                    },
                },
                message: "Discount code",
            },
        ],
        discountApplicationStrategy: DiscountApplicationStrategy.First,
    }