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.
Solved! Go to the solution
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 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.