Skip to content

Commit

Permalink
Merge pull request #207 from getbread/asi-3371-variant-pricing-changes
Browse files Browse the repository at this point in the history
ASI-3371 Don't call SDK init more than once
  • Loading branch information
fkhan-bread authored Aug 21, 2023
2 parents 386ca53 + c48b371 commit c02a232
Show file tree
Hide file tree
Showing 6 changed files with 207 additions and 174 deletions.
102 changes: 54 additions & 48 deletions view/frontend/templates/breadcheckout/cartview.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -24,84 +24,90 @@
buttonPrevent.css('height', '100%');
buttonPrevent.show();
}

let wasSetup = false;
document.configureButton = function (items) {
if (typeof window.BreadPayments !== 'undefined' || typeof window.RBCPayPlan !== 'undefined') {
let bread_sdk = null;
let config_client = "<?= /* @noEscape */ $block->getConfigClient(); ?>";
if (config_client === 'RBC') {
let config_client = "<?= /* @noEscape */ $block->getConfigClient(); ?>";
if (config_client === 'RBC') {
bread_sdk = window.RBCPayPlan;
} else {
} else {
bread_sdk = window.BreadPayments;
}
let onApproved = function onApproved(application) {};
let onCheckout = function onCheckout(application) {};
bread_sdk.setup({
integrationKey: "<?= /* @noEscape */ $block->getIntegrationKey(); ?>"
});
bread_sdk.on('INSTALLMENT:APPLICATION_DECISIONED', onApproved);
bread_sdk.on('INSTALLMENT:APPLICATION_CHECKOUT', onCheckout);
let currentCurrencyCode = "<?= /* @noEscape */ $block->getCurrentCurrencyCode(); ?>";
let itemsObject = [];
let total = 0;
for (var i = 0; i < items.length; i++) {
}

let currentCurrencyCode = "<?= /* @noEscape */ $block->getCurrentCurrencyCode(); ?>";
let itemsObject = [];
let total = 0;
for (var i = 0; i < items.length; i++) {
total += items[i]['price'] * items[i]['quantity'];
}
<?php if(!$block->isHealthcare()) : ?>
for (var i = 0; i < items.length; i++) {
}
<?php if(!$block->isHealthcare()) : ?>
for (var i = 0; i < items.length; i++) {
let item = {
name: items[i]['name'],
quantity: items[i]['quantity'],
shippingCost: {
name: items[i]['name'],
quantity: items[i]['quantity'],
shippingCost: {
value: 0,
currency: currentCurrencyCode
},
shippingDescription: '',
unitTax: {
},
shippingDescription: '',
unitTax: {
value: 0,
currency: currentCurrencyCode
},
unitPrice: {
},
unitPrice: {
currency: currentCurrencyCode,
value: items[i]['price']
},
itemUrl: items[i].detailUrl
},
itemUrl: items[i].detailUrl
};

itemsObject.push(item);
}
<?php endif; ?>
bread_sdk.registerPlacements([{
}
<?php endif; ?>
let data = {
allowCheckout: false,
domID: 'bread-checkout-btn',
order: {
currency: currentCurrencyCode,
items: itemsObject,
subTotal: {
currency: currentCurrencyCode,
items: itemsObject,
subTotal: {
value: total,
currency: currentCurrencyCode
},
totalPrice: {
},
totalPrice: {
value: total,
currency: currentCurrencyCode
},
totalDiscounts: {
},
totalDiscounts: {
value: 0,
currency: currentCurrencyCode
},
totalShipping: {
},
totalShipping: {
value: 0,
currency: currentCurrencyCode
},
totalTax: {
},
totalTax: {
value: 0,
currency: currentCurrencyCode
}
}
}]);

bread_sdk.__internal__.setInitMode('manual');
bread_sdk.__internal__.init();
}
};
if (!wasSetup) {
let onApproved = function onApproved(application) {};
let onCheckout = function onCheckout(application) {};
bread_sdk.setup({
integrationKey: "<?= /* @noEscape */ $block->getIntegrationKey(); ?>"
});
bread_sdk.on('INSTALLMENT:APPLICATION_DECISIONED', onApproved);
bread_sdk.on('INSTALLMENT:APPLICATION_CHECKOUT', onCheckout);
bread_sdk.registerPlacements([data]);
bread_sdk.setInitMode('manual');
bread_sdk.init();
wasSetup = true;
} else {
bread_sdk.registerPlacements([data]);
}
} else {
let errorInfo = {
err: 'err'
Expand Down
39 changes: 23 additions & 16 deletions view/frontend/templates/breadcheckout/catalog/product/view.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -54,24 +54,31 @@
<?php endforeach; ?>
if (typeof window.BreadPayments !== 'undefined' || typeof window.RBCPayPlan !== 'undefined') {
var bread_sdk = null;
var config_client = '<?= /* @noEscape */ $block->getConfigClient(); ?>';
if (config_client === 'RBC') {
bread_sdk = window.RBCPayPlan;
} else {
bread_sdk = window.BreadPayments;
}
var onApproved = function onApproved(application) {};
var onCheckout = function onCheckout(application) {};
let wasSetup = false;
if (!wasSetup) {
var config_client = '<?= /* @noEscape */ $block->getConfigClient(); ?>';
if (config_client === 'RBC') {
bread_sdk = window.RBCPayPlan;
} else {
bread_sdk = window.BreadPayments;
}
var onApproved = function onApproved(application) {};
var onCheckout = function onCheckout(application) {};

bread_sdk.setup({
integrationKey: integrationKey
});
bread_sdk.on('INSTALLMENT:APPLICATION_DECISIONED', onApproved);
bread_sdk.on('INSTALLMENT:APPLICATION_CHECKOUT', onCheckout);
bread_sdk.setup({
integrationKey: integrationKey
});
bread_sdk.on('INSTALLMENT:APPLICATION_DECISIONED', onApproved);
bread_sdk.on('INSTALLMENT:APPLICATION_CHECKOUT', onCheckout);

bread_sdk.registerPlacements(placementObject);
bread_sdk.setInitMode('manual');
bread_sdk.init();
bread_sdk.registerPlacements(placementObject);
bread_sdk.setInitMode('manual');
bread_sdk.init();
wasSetup = true;
} else {
bread_sdk.registerPlacements(placementObject);
bread_sdk.openExperienceForPlacement(placementObject);
}
}
});
});
Expand Down
30 changes: 19 additions & 11 deletions view/frontend/templates/breadcheckout/grouped.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<script>
<?php if ($block->getApiVersion() === 'bread_2') : ?>
require(['jquery'], function($) {
let wasSetup = false;
document.configureButton = function (items) {
if (typeof window.BreadPayments !== 'undefined' || typeof window.RBCPayPlan !== 'undefined') {
let bread_sdk = null;
Expand All @@ -30,13 +31,7 @@
} else {
bread_sdk = window.BreadPayments;
}
let onApproved = function onApproved(application) {};
let onCheckout = function onCheckout(application) {};
bread_sdk.setup({
integrationKey: "<?= /* @noEscape */ $block->getIntegrationKey(); ?>"
});
bread_sdk.on('INSTALLMENT:APPLICATION_DECISIONED', onApproved);
bread_sdk.on('INSTALLMENT:APPLICATION_CHECKOUT', onCheckout);

let currentCurrencyCode = "<?= /* @noEscape */ $block->getCurrentCurrencyCode(); ?>";
let itemsObject = [];
var total = 0;
Expand Down Expand Up @@ -66,7 +61,7 @@
itemsObject.push(item);
}
<?php endif; ?>
bread_sdk.registerPlacements([{
let data = {
allowCheckout: false,
domID: 'bread-checkout-btn',
order: {
Expand All @@ -93,9 +88,22 @@
currency: currentCurrencyCode
}
}
}]);
bread_sdk.__internal__.setInitMode('manual');
bread_sdk.__internal__.init();
};
let onApproved = function onApproved(application) {};
let onCheckout = function onCheckout(application) {};
bread_sdk.setup({
integrationKey: "<?= /* @noEscape */ $block->getIntegrationKey(); ?>"
});
bread_sdk.on('INSTALLMENT:APPLICATION_DECISIONED', onApproved);
bread_sdk.on('INSTALLMENT:APPLICATION_CHECKOUT', onCheckout);
if (!wasSetup) {
bread_sdk.registerPlacements([data]);
bread_sdk.setInitMode('manual');
bread_sdk.init();
wasSetup = true;
} else {
bread_sdk.registerPlacements([data]);
}
}
};
$(document).ready(function() {
Expand Down
2 changes: 1 addition & 1 deletion view/frontend/templates/breadcheckout/minicart.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
<script type="text/javascript">
<?php if ($block->getApiVersion() === 'bread_2') : ?>
require(['jquery'], function($) {
let wasSetup = false;
document.configureButton = function (items) {
if (typeof window.BreadPayments !== 'undefined' || typeof window.RBCPayPlan !== 'undefined') {
var currentCurrencyCode = "<?= /* @noEscape */ $block->getCurrentCurrencyCode(); ?>";
var configClient = "<?= /* @noEscape */ $block->getConfigClient(); ?>";
var breadSdk = null;
var configClient = "<?= /* @noEscape */ $block->getConfigClient(); ?>";
if (configClient === 'RBC') {
breadSdk = window.RBCPayPlan;
} else {
Expand Down
Loading

0 comments on commit c02a232

Please sign in to comment.