bold-po-klarna.js

Created by Brett Mikulik, Modified on Thu, 03 Nov 2022 at 05:26 PM by Brett Mikulik


(function() {
  function bindEvents() {
    if (typeof BOLD === "object" && BOLD.common && BOLD.common.eventEmitter) {
      BOLD.common.eventEmitter.addListener('BOLD_OPTIONS_total_changed', function(ev) {
        var klarnas = document.querySelectorAll('klarna-placement')
        if (klarnas.length) {
          for (var i in klarnas) {
            var v = klarnas[i]
            if (typeof v === 'object') {
              window.KlarnaOnsiteService = window.KlarnaOnsiteService || [];
              window.KlarnaOnsiteService.push({ eventName: 'refresh-placements', placementId: v.dataset.id });
              window.KlarnaThemeGlobals.data_purchase_amount = ev.data.option_product.priceHandler.productPrice + ev.data.total;
              window.KOSMApp.updatePurchaseAmount();
            }
          }
        }
      });
      return true;
    }
    return false;
  }
  if (!bindEvents()) {
    var cycles = 0;
    var bold_inter = setInterval(function() {
      cycles++;
      (bindEvents() || cycles > 10) && clearInterval(bold_inter);
    }, 300);
  }
})();

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select atleast one of the reasons

Feedback sent

We appreciate your effort and will try to fix the article