Discussing APIs and development related to customers, discounts, and order management.
Hi guys,
i am working on a project (Hydrogen 2, Shopify Plus) rn where we need to achieve two things at once:
1) quantity price breaks at 2 specific quantities
2) for the same products a buy x get y discount
Here some more detail on both:
1) The first break should be at min. 3 pieces -> price reduces from 40$ to 35$ per piece and the second at min. 5 pieces -> price reduces from 35$ to 30$ per piece
2) If the customer buys at least 5 Items, he should get one for free but the 5 items should still have the reduced price from 1)
My Idea was to have the price breaks as a JSON in a Metafield and use this to query the price from the Storefront API to show it in the UI and then create a Shopify Function that applies the price breaks for 1). There are two problems now:
I) the Function does not allow to apply this to multiple line items in the cart, I can only choose to use ApplyDiscountStrategy.First or ApplyDiscountStrategy.Maximum, but nut ApplyDiscountStrategy.All, I read on Shopifys GitHub, that there should be a fix but so far I have not seen this in the API docs, so how could I allow a customer to Buy 5 pieces of Product A and 5 Pieces of Product B and still get the 5-piece price break for both?
II) a buy 5 get 1 free is easy in the backend but how could this be combined with 1) as there can not be multiple discounts per product
Ideas/Questions:
- is there any way to add an item to the cart in the checkout without a discount function so I could do 2) without applying the Buy X get Y Discount, if so I could still apply 1) to the product and have quantity price break as well as a free product in the cart
- another option could be to create multiple variants per product with the 3 price points for 1) and change the variant based on the selected number of items, doing this I could combine both 1) and also 2) but what if the customer chooses 5 items, gets the variant with the price for the 5-item price break and then changes the number of items back to 4 in the cart, how can I manipulate the cart then to choose the 3-item price break variant again as the customer should not have the option to get less than 5 items from the minimum 5-item variant
- the third option would be to have some combination of both so there would be a discount 3) that reduces the price from the 5 items AND adds another item for free, but is this even possible?
- is there a release plan for ApplyDiscountStrategy.All soon?
Thanks for everyones Support
Hi, @mwmax !
1) You are right, Shopify doesn't allow youto apply the price breaks to multiple lines items in cart because the ApplyDiscountStrategy only has two values: First and Maximum. There is no ApplyDiscountStrategy.All option yet. However you can try a workaround that I thought of:
You can create a custom line item property for each product that stores the quantity price break value and then use the Function to apply the discount based on the property. For example you can add a line item property called "price_break" with the value depending on the quantity of the product. Then in your function you can use the lineItem.properties.price_break property to determine the discount amount. That way you can apply the price breaks to all the products that have the line item property.
2) You cannot combine the Buy X get Y discont with the price breaks as there can only be one discount per product. But there is another workaround. You can create a hidden product that represents the free item and then use the function to add it to the cart when the customer qualifies for the buy X get Y discount. For example you can create a product called "Free item" with a price of 0 and for example SKU of "FREE". Then in your function you can use the cart.addLineItem method to add the free item to the cart when the customer buys at least those 5 items. This way you can offer the free item without applying buy x get y discount to the products.
Now your questions:
1) You can add an item to the cart in the checkout without a discount function by using the cart.addLineItem method in your function. This method allows you to add any product to cart including hidden products. You can use this to add the free item to the cart when customer qualifies for the buy X get Y discount and the napply the price breaks to the products using the line item property workaround.
2) Creating multiple variants per product with the 3 price points is another possible solution but it has some drawbacks. One of them is the scenario that you described, where the customer changes the number of items in the cart and gets the wrong price. To avoid this, you can use the cart.changeLineItem method in your function to change the variant based on the selected number of items. This allows you to change the variant ID, quantity and properties of a line items in the cart. You can use this to update the variant ID to the correct one based on the quantity of the product. For example if the customer changes the quantity from 5 to 4 you can use the cart.changeLineItem to change the variant ID from the 5 item price break variant to the 3 item price break variant.
3) You can have a combo of both the buy X get Y discount and the price breaks by using the hidden product and the line item property workarounds. However this is not a very good solution as it involves creating extra products and properties that are not visible to the customer. A better solution would be to wait for the ApplyDiscountStrategy.All option to be available or just use a third-party app that can handle complex discounts.
4) You can follow the Shopify Functions GitHub repository to stay updated on the latest developments changes.
Let me know if you have any other questions!
Hi @ignelis_,
first of all thank you for the quick reply, awesome!
1) so you mean you would apply the discount not on base of the variant but on the items that have the specific line item properties? This sounds promising to me and I will try this. But I am not sure right now if this would apply different price breaks to the products if I have Product A 5x and Product B 3x, that Product A would get the min 5 Pricebreak and Product B the min 3 Pricebreak? Or maybe I get it wrong.
3) I agree, the problem is we have this logic since 10 years on our custom shop and we migrate to shopify so I have to find a solution and can not wait until the apply all is available... I just thought about creating a bundle if the user has 5+ of the product in the cart, not sure if this would be a valid solution, do you have an opinion on that?
Thanks for your helpful answer.
Hi Mwmax,
It does sound like you have quite a complex requirement with mixing different discount rules. Unfortunately, as of now, Shopify doesn't support "all" as a value for the DiscountApplicationStrategy object as you've mentioned - but this may be supported in the future.
Addressing your ideas/questions:
You can add an item to the cart without applying a discount by using the Storefront API checkoutLineItemsAdd
mutation. However, note that this requires the checkout ID.
Creating multiple variants per product is a potential solution, but as you've noted, managing this could be complex and error-prone. You would need to monitor the cart and update the variant whenever the quantity changes, which could potentially lead to a poor user experience if not handled properly.
Combining the discounts into one that reduces the price and provides a free item is also a potential solution. However, this would require custom logic in your app to manage this. You could potentially use the checkoutLineItemsUpdate
mutation to modify the line items in the checkout when certain conditions are met.
I hope this helps! Let me know if you have any other questions.
Liam | Developer Advocate @ Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog
Hi @Liam, thanks for the reply!
I would like to explore 3) on the weekend as this sounds still interesting to me. Do you think there is also a way to apply this then to multiple line items or wouldn't I get rid of that problem with this solution?
The problem is I don't have too many options to change our logic as we did this since 10 years and the customers are used to this.