Totals API - Unlimited Discounts Manager App
Some stores use Cart Drawers / Mini-Carts in their themes, instead of using the cart page, by default our app will replace the total value in the cart page of the store to show the discounts and the final value of the order. If you want to show these values in your Cart Drawer / Mini-Carts HTML it's required to implement this API via a developer.
Using the Totals API makes it possible to show the totals on any page of your store, you have the freedom to show the values on any interface that you want, just retrieving the values using our API.
The totals object contains all these values: discount value, original cart value, final cart value, discount per line item, original price per line item, final line item price.
All these values are available in cents(Shopify way of showing prices) and also formatted, using the default currency of the store.
To see real examples of the totals API responses scroll down.
Using the API
It's a javascript API that you can call using:
window.RevyDiscounts.api.getTotal(total => {console.log(total)})
- Response when a discount matches
- Response when no discount matches the shopping cart
1. Response when a discount matches
When a discount matches the response will have 2 keys with values:
{cart: {...}, totals: {...}}
The cart is the shopping cart JSON object and the totals are the totals from our Discounts app.
Example:
{ "cart": { "token": "b63f8d365b7ffabecf0dce18fd3f2524", "note": null, "attributes": { "revy_bundle_add": "515786" }, "original_total_price": 10000, "total_price": 10000, "total_discount": 0, "total_weight": 0, "item_count": 4, "items": [ { "id": 31429939363915, "properties": {}, "quantity": 4, "variant_id": 31429939363915, "key": "31429939363915:602729442495ca783bb76bffbc8f4b09", "title": "Black & Decker Stainless Steel Electric Kettles Newl - Plastic", "price": 2500, "original_price": 2500, "discounted_price": 2500, "line_price": 10000, "original_line_price": 10000, "total_discount": 0, "discounts": [], "sku": "SV271532", "grams": 0, "vendor": "The Santa Saver", "taxable": false, "product_id": 11142279559, "product_has_only_default_variant": false, "gift_card": false, "final_price": 2500, "final_line_price": 10000, "url": "/products/black-decker-stainless-steel-electric-kettle?variant=31429939363915", "featured_image": { "aspect_ratio": 0.991, "alt": "Black & Decker Stainless Steel Electric Kettles Newl", "height": 932, "url": "https://cdn.shopify.com/s/files/1/2197/6721/products/plastico.jpg?v=1575045447", "width": 924 }, "image": "https://cdn.shopify.com/s/files/1/2197/6721/products/plastico.jpg?v=1575045447", "handle": "black-decker-stainless-steel-electric-kettle", "requires_shipping": true, "product_type": "", "product_title": "Black & Decker Stainless Steel Electric Kettles Newl", "product_description": "\nA pour-fect kettle. With a sleek design, this Black & Decker electric kettle is built to last.\n\n360° swivel base is designed for right- or left-handed use.\nRapid boil feature heats water faster than a microwave.\nBuilt-in scale filter keeps mineral deposits at bay.\nHand wash\nManufacturer's 1-year limited warranty\n1500 watts\n7 3/16-cup capacity\nModel no. JKC650\n\n", "variant_title": "Plastic", "variant_options": [ "Plastic" ], "options_with_values": [ { "name": "Material", "value": "Plastic" } ], "line_level_discount_allocations": [], "line_level_total_discount": 0 } ], "requires_shipping": true, "currency": "USD", "items_subtotal_price": 10000, "cart_level_discount_applications": [] }, "totals": { "final": 9900, "discount": 100, "original": 10000, "formatted": { "final": "<span class=money>$99.00</span>", "discount": "<span class=money>$1.00</span>", "original": "<span class=money>$100.00</span>" }, "total_per_line_item": [ { "key": "31429939363915:602729442495ca783bb76bffbc8f4b09", "final": 9900, "original": 10000, "discount": 100, "formatted": { "final": "<span class=money>$99.00</span>", "original": "<span class=money>$100.00</span>", "discount": "<span class=money>$1.00</span>" }, "variant_id": 31429939363915, "product_id": 11142279559, "properties": {}, "quantity": 4, "item_price": { "final": 2475, "original": 2500, "discount": 25, "formatted": { "final": "<span class=money>$24.75</span>", "original": "<span class=money>$25.00</span>", "discount": "<span class=money>$0.25</span>" } } } ] } }
2. Response when no discount matches the shopping cart
When NONE discount matches the shopping cart, our API will return "null" in the "totals" key value:
{cart: {...}, totals: null}
The cart is the shopping cart JSON object and the totals will be null.
Example:
{ "cart": { "token": "b63f8d365b7ffabecf0dce18fd3f2524", "note": null, "attributes": { "revy_bundle_add": "515786" }, "original_total_price": 10000, "total_price": 10000, "total_discount": 0, "total_weight": 0, "item_count": 4, "items": [ { "id": 31429939363915, "properties": {}, "quantity": 4, "variant_id": 31429939363915, "key": "31429939363915:602729442495ca783bb76bffbc8f4b09", "title": "Black & Decker Stainless Steel Electric Kettles Newl - Plastic", "price": 2500, "original_price": 2500, "discounted_price": 2500, "line_price": 10000, "original_line_price": 10000, "total_discount": 0, "discounts": [], "sku": "SV271532", "grams": 0, "vendor": "The Santa Saver", "taxable": false, "product_id": 11142279559, "product_has_only_default_variant": false, "gift_card": false, "final_price": 2500, "final_line_price": 10000, "url": "/products/black-decker-stainless-steel-electric-kettle?variant=31429939363915", "featured_image": { "aspect_ratio": 0.991, "alt": "Black & Decker Stainless Steel Electric Kettles Newl", "height": 932, "url": "https://cdn.shopify.com/s/files/1/2197/6721/products/plastico.jpg?v=1575045447", "width": 924 }, "image": "https://cdn.shopify.com/s/files/1/2197/6721/products/plastico.jpg?v=1575045447", "handle": "black-decker-stainless-steel-electric-kettle", "requires_shipping": true, "product_type": "", "product_title": "Black & Decker Stainless Steel Electric Kettles Newl", "product_description": "\nA pour-fect kettle. With a sleek design, this Black & Decker electric kettle is built to last.\n\n360° swivel base is designed for right- or left-handed use.\nRapid boil feature heats water faster than a microwave.\nBuilt-in scale filter keeps mineral deposits at bay.\nHand wash\nManufacturer's 1-year limited warranty\n1500 watts\n7 3/16-cup capacity\nModel no. JKC650\n\n", "variant_title": "Plastic", "variant_options": [ "Plastic" ], "options_with_values": [ { "name": "Material", "value": "Plastic" } ], "line_level_discount_allocations": [], "line_level_total_discount": 0 } ], "requires_shipping": true, "currency": "USD", "items_subtotal_price": 10000, "cart_level_discount_applications": [] }, "totals": null }
Please let us know if you have any problems implementing this API, we will be happy to help at [email protected] ;).