TL;DR: Using the GraphQL Admin API to create products on the fly. When added to the cart via JS, discounts tied to a dynamic collection (which should include the new product) aren’t applied until the cart is changed again. Need a workaround to make the discount apply immediately.
Description:
I am using the GraphQL Admin API to create products on demand based on customer actions in the storefront. The product creation is triggered via JavaScript running directly in the storefront. After a product is successfully created via the API, the same JavaScript code adds the newly created product to the customer’s cart.
The issue I’m encountering is with discounts. We have discounts configured to apply to a dynamic collection. This collection is set up to automatically include new products, so newly created products should be eligible for the discount.
However, the discount is not applied immediately when the product is added to the cart. The discount only appears to be applied after a subsequent change to the cart (e.g., quantity change, removal of an item, etc.). The customer therefore does not see the discounted price when the item is initially added, which is causing confusion and impacting the user experience.
Steps to Reproduce:
- Customer performs an action in the storefront that triggers product creation via the GraphQL Admin API.
- JavaScript in the storefront adds the newly created product to the cart.
- Observe the cart: the discount associated with the dynamic collection is not applied to the newly added product.
- Make any change to the cart (e.g., change quantity of any item, remove an item).
- Observe the cart: the discount is now correctly applied to the newly added product.
Expected Behavior:
The discount should be applied to the newly created product immediately upon being added to the cart, as the product is automatically included in the dynamic collection to which the discount applies.
Current Behavior:
The discount is only applied after a subsequent cart modification. (Limitation of the Shopify platform according to the Shopify Support Team)
Impact:
This delay in discount application creates a poor user experience. Customers expect to see the discounted price immediately. The current behavior makes it appear as if the discount is not working or that the newly created product is not eligible for the discount.
Question:
Is there a known workaround or solution to ensure that discounts are applied immediately to newly created products added to the cart in this scenario? Any insights or suggestions would be greatly appreciated.