Skip to content

Commit

Permalink
[CHK-7187] Adding promise logic solving for race condition
Browse files Browse the repository at this point in the history
  • Loading branch information
boldjoshshea committed Jan 10, 2025
1 parent 0996a4b commit 4b4b915
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
1 change: 0 additions & 1 deletion Observer/Product/ExpressPayBeforeAddToCartObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,5 @@ public function execute(Observer $observer): void
$this->checkoutSession->clearQuote();

$this->cartRepository->save($quote);
$this->checkoutSession->setQuoteId($quote->getId());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ define(
*/
return function (requirements) {
const payload = {};
if (window.checkoutConfig.bold.payment_type_clicked == 'apple') {
if (window.checkoutConfig.quoteData.entity_id === ''
&& (window.checkoutConfig.bold.payment_type_clicked === 'apple'
|| window.checkoutConfig.bold.payment_type_clicked === "google")) {
payload.totals = {
order_total: 0,
order_balance: 1000,
Expand Down
16 changes: 12 additions & 4 deletions view/frontend/web/js/model/spi.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ define([
localStorage.setItem(AGREEMENT_DATE_KEY, currentTime.toString());
return true;
};
let onClickPromise = null;

/**
* Fastlane init model.
Expand Down Expand Up @@ -114,6 +115,10 @@ define([
}

try {
if (onClickPromise !== null) {
await onClickPromise;
onClickPromise = null;
}
return await onUpdatePaymentOrderCallback(paymentType, paymentPayload);
} catch (e) {
console.error(e);
Expand All @@ -139,7 +144,7 @@ define([
throw e;
}
},
'onRequireOrderData': async function (requirements) {
'onRequireOrderData': function (requirements) {
try {
return onRequireOrderDataCallback(requirements);
} catch (e) {
Expand All @@ -155,9 +160,12 @@ define([
'onClickPaymentOrder': async (paymentType, paymentPayload) => {
const pageSource = paymentPayload.containerId.replace('express-pay-buttons-', '');
window.checkoutConfig.bold.payment_type_clicked = paymentPayload?.payment_data?.payment_type;

try {
onClickPaymentOrderCallback(pageSource);
try {
if (paymentPayload?.payment_data?.payment_type !== "apple" || paymentPayload?.payment_data?.payment_type !== "google") {
await onClickPaymentOrderCallback(pageSource);
} else {
onClickPromise = onClickPaymentOrderCallback(pageSource);
}
} catch (e) {
console.error(e);
fullScreenLoader.stopLoader();
Expand Down

0 comments on commit 4b4b915

Please sign in to comment.