Totals API - Showing Bundle totals and discounts on your theme
This Javascript API will retrieve from our app the Bundle totals and discounts, the response includes the totals for the entire shopping cart and per each variant.
Here is how you can use the Totals API:
window.RevyBundle.api.getTotal(response => { console.log(response) })
The API response will be an object like this:
{ bundleTotal: (bundle totals object) originalCart: (shopify cart object) }
The response of this API may come in 2 formats, the complete response(let's call Response 1) when a Bundle matches, and there is a Bundle discount, and a response when there is no Bundle discount that matches(Response 2).
- The difference in the responses are:
Response 1 (when a Bundle matches): The object response.bundleTotal will have the formatted node and the per_variant object, the per_variant object details how much are the prices for every variant of the cart, it returns the final price, original price, and discount value for every variant.
Response 2 (when no Bundle discount matches): This response will not have the formatted node and the per_variant object since there is no Bundle discount to apply.
- Recommendation of implementation:
Always check if the response.bundleTotal.discount is greater than zero(if response.bundleTotal.discount > 0), when it is true you use the bundleTotal node values, if is false just use the normal cart object (response.originalCart) because there is no Bundle Discount to apply.
Below are the examples of both responses(1 and 2).
Response 1 Example - When a Bundle discount matches:
{ "bundleTotal": { "final": 4853, "original": 5393, "discount": 540, "formatted": { "final": "<span class=money>$48.53</span>", "original": "<span class=money>$53.93</span>", "discount": "<span class=money>$5.40</span>" }, "per_variant": [ { "key": "51309045127:a919e324bdaf6c7bce66685cb7248d73", "variant_id": 51309045127, "product_id": 11142301319, "quantity": 1, "final": 1255, "original": 1395, "discount": 140, "unit_price": 1395, "formatted": { "final": "<span class=money>$12.55</span>", "original": "<span class=money>$13.95</span>", "discount": "<span class=money>$1.40</span>" }, "item_price": { "final": 1255, "original": 1395, "discount": 140, "formatted": { "final": "<span class=money>$12.55</span>", "original": "<span class=money>$13.95</span>", "discount": "<span class=money>$1.40</span>" } } }, { "key": "31429939363915:602729442495ca783bb76bffbc8f4b09", "variant_id": 31429939363915, "product_id": 11142279559, "quantity": 2, "final": 3598, "original": 3998, "discount": 400, "unit_price": 1999, "formatted": { "final": "<span class=money>$35.98</span>", "original": "<span class=money>$39.98</span>", "discount": "<span class=money>$4.00</span>" }, "item_price": { "final": 1799, "original": 1999, "discount": 200, "formatted": { "final": "<span class=money>$17.99</span>", "original": "<span class=money>$19.99</span>", "discount": "<span class=money>$2.00</span>" } } } ], "enabledNewDiscounts": true }, "originalCart": { "token": "cc293abc514a5690122df77ad55192c3", "note": null, "attributes": { "revy_bundle_add": "80083" }, "original_total_price": 5393, "total_price": 5393, "total_discount": 0, "total_weight": 0, "item_count": 3, "items": [ { "id": 51309045127, "properties": {}, "quantity": 1, "variant_id": 51309045127, "key": "51309045127:a919e324bdaf6c7bce66685cb7248d73", "title": "Calphalon Traditional Ice Cream Scoop 89", "price": 1395, "original_price": 1395, "discounted_price": 1395, "line_price": 1395, "original_line_price": 1395, "total_discount": 0, "discounts": [], "sku": "SV52048", "grams": 0, "vendor": "me", "taxable": true, "product_id": 11142301319, "product_has_only_default_variant": true, "gift_card": false, "final_price": 1395, "final_line_price": 1395, "url": "/products/a-41?variant=51309045127", "featured_image": { "aspect_ratio": 1, "alt": "Calphalon Traditional Ice Cream Scoop 89", "height": 1200, "url": "https://cdn.shopify.com/s/files/1/2197/6721/products/logo.png?v=1569311698", "width": 1200 }, "image": "https://cdn.shopify.com/s/files/1/2197/6721/products/logo.png?v=1569311698", "handle": "a-41", "requires_shipping": true, "product_type": "", "product_title": "Calphalon Traditional Ice Cream Scoop 89", "product_description": "Product Description", "variant_title": null, "variant_options": [ "Default Title" ], "options_with_values": [ { "name": "Title", "value": "Default Title" } ], "line_level_discount_allocations": [], "line_level_total_discount": 0 }, { "id": 31429939363915, "properties": {}, "quantity": 2, "variant_id": 31429939363915, "key": "31429939363915:602729442495ca783bb76bffbc8f4b09", "title": "Black & Decker Stainless Steel Electric Kettles Newl - Plastic", "price": 1999, "original_price": 1999, "discounted_price": 1999, "line_price": 3998, "original_line_price": 3998, "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": 1999, "final_line_price": 3998, "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": "Product Description", "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": 5393, "cart_level_discount_applications": [] } }
Response 2 Example - When no Bundle discount matches:
{ "bundleTotal": { "final": 5393, "original": 5393, "discount": 0 }, "originalCart": { "token": "cc293abc514a5690122df77ad55192c3", "note": null, "attributes": { "revy_bundle_add": "80083" }, "original_total_price": 5393, "total_price": 5393, "total_discount": 0, "total_weight": 0, "item_count": 3, "items": [ { "id": 51309045127, "properties": {}, "quantity": 1, "variant_id": 51309045127, "key": "51309045127:a919e324bdaf6c7bce66685cb7248d73", "title": "Calphalon Traditional Ice Cream Scoop 89", "price": 1395, "original_price": 1395, "discounted_price": 1395, "line_price": 1395, "original_line_price": 1395, "total_discount": 0, "discounts": [], "sku": "SV52048", "grams": 0, "vendor": "me", "taxable": true, "product_id": 11142301319, "product_has_only_default_variant": true, "gift_card": false, "final_price": 1395, "final_line_price": 1395, "url": "/products/a-41?variant=51309045127", "featured_image": { "aspect_ratio": 1, "alt": "Calphalon Traditional Ice Cream Scoop 89", "height": 1200, "url": "https://cdn.shopify.com/s/files/1/2197/6721/products/logo.png?v=1569311698", "width": 1200 }, "image": "https://cdn.shopify.com/s/files/1/2197/6721/products/logo.png?v=1569311698", "handle": "a-41", "requires_shipping": true, "product_type": "", "product_title": "Calphalon Traditional Ice Cream Scoop 89", "product_description": "Product Description", "variant_title": null, "variant_options": [ "Default Title" ], "options_with_values": [ { "name": "Title", "value": "Default Title" } ], "line_level_discount_allocations": [], "line_level_total_discount": 0 }, { "id": 31429939363915, "properties": {}, "quantity": 2, "variant_id": 31429939363915, "key": "31429939363915:602729442495ca783bb76bffbc8f4b09", "title": "Black & Decker Stainless Steel Electric Kettles Newl - Plastic", "price": 1999, "original_price": 1999, "discounted_price": 1999, "line_price": 3998, "original_line_price": 3998, "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": 1999, "final_line_price": 3998, "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": "Product Description", "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": 5393, "cart_level_discount_applications": [] } }
For questions or feedback please contact us at [email protected].