Add shouldRender method for the context bootstrappers

This commit is contained in:
Mészáros Róbert 2020-04-09 10:49:37 +03:00
parent 9f1a633ad9
commit 5990d9766b
4 changed files with 34 additions and 27 deletions

View file

@ -6,18 +6,11 @@ class CheckoutBootstap {
}
init() {
const buttonWrapper = PayPalCommerceGateway.button.wrapper;
const cancelWrapper = PayPalCommerceGateway.button.cancel_wrapper;
if (!document.querySelector(buttonWrapper)) {
if (!this.shouldRender()) {
return;
}
if (document.querySelector(cancelWrapper)) {
return;
}
const renderer = new Renderer(buttonWrapper);
const renderer = new Renderer(PayPalCommerceGateway.button.wrapper);
jQuery(document.body).on('updated_checkout', () => {
renderer.render(this.configurator.configuration());
@ -31,17 +24,25 @@ class CheckoutBootstap {
'input[name="payment_method"]:checked').val();
if (currentPaymentMethod !== 'ppcp-gateway') {
jQuery(buttonWrapper).hide();
jQuery(PayPalCommerceGateway.button.wrapper).hide();
jQuery('#place_order').show();
}
else {
jQuery(buttonWrapper).show();
jQuery(PayPalCommerceGateway.button.wrapper).show();
jQuery('#place_order').hide();
}
});
renderer.render(this.configurator.configuration());
}
shouldRender() {
if (document.querySelector(PayPalCommerceGateway.button.cancel_wrapper)) {
return false;
}
return document.querySelector(PayPalCommerceGateway.button.wrapper);
}
}
export default CheckoutBootstap;