Dedicated to the Hydrogen framework, headless commerce, and building custom storefronts using the Storefront API.
Hi Shopify and the amazing Shopify Community!
Thanks for all the amazing endpoints, dev tools and apps provided to extend Shopify!
While developing an admin-embedded app myself, I found myself creating code to essentially check what PriceRules are applicable to an order. Shopify obviously has code to do this already so that it can check if a typed in discount code can be used before check out and what the discount if applied.
Is that functionality exposed to developers anywhere? I could not find a way to implement it using the PriceRule or DiscountCode API or GraphQl reference.
If not it could be quite useful for developers who want to work with new incentive ideas but don't want to necessarily create a parallel discount handling system and database so I'd like to request it. My apologies if this is the incorrect forum for API endpoint requests.
Kind regards,
97
Solved! Go to the solution
This is an accepted solution.
Hey again,
Apologies for the slower response this time around, I was away at our Unite conference all last week.
Thanks a lot for getting back to me with this use-case though, things are much clearer now. I'll write up a feature request for this now!
Josh | 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 the Shopify Help Center or the Shopify Blog
Hey there,
I would say this was the most applicable forum for a request like this one, would you be able to share any additional details on your use case for this?
Josh | 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 the Shopify Help Center or the Shopify Blog
Thanks for the quick reply Josh,
Sure! I can provide an example use case. My actual use case is a little 'out there' from what I can tell so I'll try to use an example application that is a bit more to the point.
Let's say we want to make an app that tracks all the cart updates that shoppers make and reports back to the seller what PriceRules could have been triggered at each stage of their carts' life cycles on the Shopify Admin Panel.
This app could then 'dry run' price rules to see how often they'd be triggered, or how close they are to being triggered, before making them live on a shop. The reported information from the app could then be used for many things including increasing the amount of profit that up sells and cross-sells triggered by PriceRules create and when those discounts should be offered to get users to change their cart to something more favourable.
To make such an app with Shopify's current solutions I think you would have to:
1) pull in all of the seller's PriceRules from Shopify using the admin API or GraphQl
2) receive webhook updates for the cart creation and updates
3) re-create Shopify's price rule checking code to loop through all of the price rules to see if any of them are applicable to the cart's current state. Or you'd need to create your own price rule system which isn't really where the app's value is.
Instead it would be great if the app could focus on it's core value, it's reporting, and let shopify run the price rule checking like it already does for discount codes applied at check out.
In this case, the app would be written like this:
1) receive webhook updates for cart creation and updates.
2) send the cart's state (or for other apps, the order's state) to a shopify endpoint that responds with price rules that are matched, and how they stack.
3) Store the responses in a database and write the reporting code.
Essentially, I'm trying to not re-write the code that shopify uses to compare price rules with an order or cart to see if they are valid.
This is an accepted solution.
Hey again,
Apologies for the slower response this time around, I was away at our Unite conference all last week.
Thanks a lot for getting back to me with this use-case though, things are much clearer now. I'll write up a feature request for this now!
Josh | 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 the Shopify Help Center or the Shopify Blog
No problem at all Josh!
Hope you had a great conference and thanks for submitting the feature request
This looks pretty promising! I'll try it out to see if it works for a use case where you want to check whether or not a Shopify discount applies, without necessarily applying the discount right away and report back
you can use the Checkout API for this purpose but you'll have to turn your app into a sale channel. Just create a checkout by passing line_items and discount_code, and check applied_discount.applicalbe on the response.