Callbacks API - Events that run when some Bundle action happens

Callbacks / Events should be used if you want to run a command after an action is made, we have these 3 types of callbacks available for now:

  • onReady - Runs after Bundle Script is loaded
  • onMatchDiscountCallbacks - Run on cart page if a Bundle discount matches
  • onAddBundle - Runs after a bundle is added to the cart using the Bundle button
  • onLoad - Runs after a Bundle loads in the page

onReady

This callback runs after the Bundle script is fully loaded.

How to use
<script>
window.revyBundleDataLayer = window.revyBundleDataLayer || []; 
window.revyBundleDataLayer.push({onReady: function() {   	
console.log("Bundle onReady"); }}); 
</script>

onMatchDiscountCallbacks

This callback runs on cart page if the cart items match a Bundle(or multiple). The argument passed in the callback will be an Array with the variants that match the Bundle, the variant object will include the totals.

How to use
<script>
window.revyBundleDataLayer = window.revyBundleDataLayer || [];
window.revyBundleDataLayer.push({onMatchDiscountCallbacks: function(variants) {
  	console.log("Bundle: onMatchDiscountCallbacks");
	console.log(variants)
}});
</script>
Response example
[
  {
    "variant_id": 32039244693559,
    "original_price": 4000,
    "discount_value": 350,
    "discounted_price": 3650,
    "formatted": {
      "original": "$40.00",
      "discount": "$3.50",
      "discounted": "$36.50"
    },
    "number": {
      "original": 4000,
      "discount": 350,
      "discounted": 3650
    }
  },
  {
    "variant_id": 32039244628023,
    "original_price": 4000,
    "discount_value": 350,
    "discounted_price": 3650,
    "formatted": {
      "original": "$40.00",
      "discount": "$3.50",
      "discounted": "$36.50"
    },
    "number": {
      "original": 4000,
      "discount": 350,
      "discounted": 3650
    }
  }
]

onAddBundle

This callback runs when a Bundle is added to the cart using the Bundle widget, pressing the Bundle button.

IMPORTANT: This callback will run just if the redirect setting is set to "Not Redirect", if your Bundle is redirecting after adds a Bundle to the cart this callback will not run, switch the setting to "Not Redirect" if you want to use this callback.

How to use
<script>
window.revyBundleDataLayer = window.revyBundleDataLayer || [];
window.revyBundleDataLayer.push({onAddBundle: function(response) {
  	console.log("Bundle: onAddBundle");
	console.log(response)
}})
</script>
Response example
{
  "cartUpdate": {
    "314299393639151": 2
  },
  "items": [
    {
      "quantity": 1,
      "product": {
        "id": 179588826,
        "shop_id": 1,
        "title": "Black & Decker Stainless Steel Electric Kettles Newl",
        "image": "https://cdn.shopify.com/s/files/1/2197/6721/products/B_D_Electric_Kettle.jpg?v=1502924651",
        "product_id": 11142279559,
        "variants": [
          {
            "id": 314299393639151,
            "price": "19.99",
            "title": "Plastic",
            "inventory_policy": "deny",
            "inventory_quantity": 10,
            "inventory_management": "shopify",
            "image": "https://cdn.shopify.com/s/files/1/2197/6721/products/plastico.jpg?v=1575045447"
          },
          {
            "id": 31430041108555,
            "price": "19.99",
            "title": "Stainless",
            "inventory_policy": "deny",
            "inventory_quantity": 20,
            "inventory_management": "shopify",
            "image": "https://cdn.shopify.com/s/files/1/2197/6721/products/B_D_Electric_Kettle.jpg?v=1502924651"
          }
        ],
        "bundle_id": 66588,
        "handle": "black-decker-stainless-steel-electric-kettle",
        "created_at": "2020-08-03T13:38:31.801Z",
        "updated_at": "2020-08-03T13:38:31.801Z",
        "hideVariantSelector": false
      },
      "variant_id": 314299393639151,
      "price": 1799.1
    },
    {
      "quantity": 2,
      "product": {
        "id": 179588826,
        "shop_id": 1,
        "title": "Black & Decker Stainless Steel Electric Kettles Newl",
        "image": "https://cdn.shopify.com/s/files/1/2197/6721/products/B_D_Electric_Kettle.jpg?v=1502924651",
        "product_id": 11142279559,
        "variants": [
          {
            "id": 314299393639151,
            "price": "19.99",
            "title": "Plastic",
            "inventory_policy": "deny",
            "inventory_quantity": 10,
            "inventory_management": "shopify",
            "image": "https://cdn.shopify.com/s/files/1/2197/6721/products/plastico.jpg?v=1575045447"
          },
          {
            "id": 31430041108555,
            "price": "19.99",
            "title": "Stainless",
            "inventory_policy": "deny",
            "inventory_quantity": 20,
            "inventory_management": "shopify",
            "image": "https://cdn.shopify.com/s/files/1/2197/6721/products/B_D_Electric_Kettle.jpg?v=1502924651"
          }
        ],
        "bundle_id": 66588,
        "handle": "black-decker-stainless-steel-electric-kettle",
        "created_at": "2020-08-03T13:38:31.801Z",
        "updated_at": "2020-08-03T13:38:31.801Z",
        "hideVariantSelector": false
      },
      "variant_id": 314299393639151,
      "price": 1799.1
    }
  ]
}

onLoad

This callback runs when some Bundle is loaded in the page, be aware that this callback can run multiple times in the same loaded page depending on your arrangement.

How to use
<script>
window.revyBundleDataLayer = window.revyBundleDataLayer || [];
window.revyBundleDataLayer.push({onLoad: function() {
  	console.log("Bundle onLoad");
}});
</script>

Still need help? Contact Us Contact Us