I am building an app to apply discounts based on the cart subtotalAmount and I have two extensions:
Theme App Extension to add an app block to the cart with a progressbar that shows how close you are to the next discount based on the current cart subtotalAmount.
a discount function to get and config discounts
How can I get the value of the cart subtotalAmount in my Theme Extension App block and the configured discounts so when the merchant config the discounts in the app UI they show in the Theme App extension block ?
You should be able to retrieve the cart data using an API call to /cart.js, which provides the subtotal amount in cents. Once you have the subtotal, you can fetch the discount configurations from your app’s backend via an API endpoint. These discounts are typically set up by the merchant in your app’s UI.
With both the subtotalAmount and discounts retrieved, you can dynamically render the applicable discounts in your Theme Extension block. To ensure the displayed information stays current, consider re-fetching data whenever the cart is updated and secure communication between the Theme Extension and your app backend using OAuth tokens or signed requests.