Hide cart buttons when intent changed

This commit is contained in:
Alex P 2023-02-15 16:50:34 +02:00
parent 4ae82b704a
commit 5dd0931c0f
No known key found for this signature in database
GPG key ID: 54487A734A204D71
5 changed files with 122 additions and 0 deletions

View file

@ -1,4 +1,5 @@
import CartActionHandler from '../ActionHandler/CartActionHandler';
import {setVisible} from "../Helper/Hiding";
class CartBootstrap {
constructor(gateway, renderer, errorHandler) {
@ -16,6 +17,26 @@ class CartBootstrap {
jQuery(document.body).on('updated_cart_totals updated_checkout', () => {
this.render();
fetch(
this.gateway.ajax.cart_script_params.endpoint,
{
method: 'GET',
credentials: 'same-origin',
}
)
.then(result => result.json())
.then(result => {
if (! result.success) {
return;
}
const newParams = result.data;
const reloadRequired = this.gateway.url_params.intent !== newParams.intent;
// TODO: should reload the script instead
setVisible(this.gateway.button.wrapper, !reloadRequired)
});
});
}