Hello.
We need to realize the following scenario.
We have a specific product “A”, when adding it to the cart we need to apply a discount using Shopify Function.
The discount should only apply to one specific line item “A”, meaning that if there are 2 line items “A” in the cart, the discount will only apply to one line item “A”.
If product ‘A’ is added to cart, we should prevent the user from applying discount codes on Checkout by entering them in the discount field displaying an error message. We should also disallow the application of automatic discounts.
Is it possible to implement something similar with the current Shopify Functions functionality ?
Shopify Scripts has methods that allow you to apply a discount to a specific line item, as well as cancel a discount code entered by the user. We have referred to the Product Discount API documentation.
In the section “Migrating from scripts to functions” ( https://shopify.dev/docs/api/functions/reference/product-discounts#migrating-from-scripts-to-functions ) there is the following table ( https://take.ms/sL38Cl ).
But it seems to us that there are inaccuracies in the documentation regarding migration (described below), we contacted Shopify support but they said they don’t provide support in this area.
№1
The table has the following description, “Use a product variant to limit the number of times that you want to apply the discount” ( https://take.ms/B75p6 ). In "Product Discount API " in “FunctionResult” we can specify only “Product Variant Id” and “Quantity” ( https://take.ms/U9XBWG ) in the “FunctionResult”, based on the documentation.
This means that it is possible to limit the discount application by “Quantity” and “Variant Id”, but not by a specific line item.
For example, we have several line items in the cart with the same variant and one of them has property “discount_target”. For the line item with property “discount_target” we need to apply a discount.
Based on the documentation that is described in “FunctionResult”, there is no method to apply a discount to a particular line item. Does this mean that currently applying a discount to a specific line item is not possible using Shopify Functions ?
№2
The table has the following description: “Use a Product discount or Order discount function that contains the necessary logic. For example, you can use conditions to exclude a discount from applying.” ( https://take.ms/y9E2u )
The description mentions “use conditions to exclude a discount” ( https://take.ms/DMHvC ).
In “Product Discount API” in “FunctionResult” or in “Order Discount API” in “FunctionResult” there is a method that applies a discount ( https://take.ms/wruZZ ), but there is no method to exclude a discount, based on the documentation.
How should the discount exclusion work using Shopify Functions then, based on the description in the documentation “Use a Product discount or Order discount function that contains the necessary logic. For example, you can use conditions to exclude a discount from applying.” ?
Also, there is no mention in the documentation about excluding automatic discounts.