mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
Add shouldRender method for the context bootstrappers
This commit is contained in:
parent
9f1a633ad9
commit
5990d9766b
4 changed files with 34 additions and 27 deletions
|
@ -6,13 +6,11 @@ class CartBootstrap {
|
|||
}
|
||||
|
||||
init() {
|
||||
const buttonWrapper = PayPalCommerceGateway.button.wrapper;
|
||||
|
||||
if (!document.querySelector(buttonWrapper)) {
|
||||
if (!this.shouldRender()) {
|
||||
return;
|
||||
}
|
||||
|
||||
const renderer = new Renderer(buttonWrapper);
|
||||
const renderer = new Renderer(PayPalCommerceGateway.button.wrapper);
|
||||
|
||||
jQuery(document.body).on('updated_cart_totals updated_checkout', () => {
|
||||
renderer.render(this.configurator.configuration());
|
||||
|
@ -20,6 +18,10 @@ class CartBootstrap {
|
|||
|
||||
renderer.render(this.configurator.configuration());
|
||||
}
|
||||
|
||||
shouldRender() {
|
||||
return document.querySelector(PayPalCommerceGateway.button.wrapper);
|
||||
}
|
||||
}
|
||||
|
||||
export default CartBootstrap;
|
|
@ -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;
|
|
@ -6,13 +6,11 @@ class MiniCartBootstap {
|
|||
}
|
||||
|
||||
init() {
|
||||
const miniCartWrapper = PayPalCommerceGateway.button.mini_cart_wrapper;
|
||||
|
||||
if (!document.querySelector(miniCartWrapper)) {
|
||||
if (!this.shouldRender()) {
|
||||
return;
|
||||
}
|
||||
|
||||
const renderer = new Renderer(miniCartWrapper);
|
||||
const renderer = new Renderer(PayPalCommerceGateway.button.mini_cart_wrapper);
|
||||
|
||||
jQuery(document.body).
|
||||
on('wc_fragments_loaded wc_fragments_refreshed', () => {
|
||||
|
@ -21,6 +19,10 @@ class MiniCartBootstap {
|
|||
|
||||
renderer.render(this.configurator.configuration());
|
||||
}
|
||||
|
||||
shouldRender() {
|
||||
return document.querySelector(PayPalCommerceGateway.button.mini_cart_wrapper)
|
||||
}
|
||||
}
|
||||
|
||||
export default MiniCartBootstap;
|
|
@ -5,17 +5,11 @@ import SingleProductConfig from './SingleProductConfig';
|
|||
|
||||
class SingleProductBootstap {
|
||||
init() {
|
||||
const buttonWrapper = PayPalCommerceGateway.button.wrapper;
|
||||
|
||||
if (!document.querySelector(buttonWrapper)) {
|
||||
if (!this.shouldRender()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!document.querySelector('form.cart')) {
|
||||
return;
|
||||
}
|
||||
|
||||
const renderer = new Renderer(buttonWrapper);
|
||||
const renderer = new Renderer(PayPalCommerceGateway.button.wrapper);
|
||||
const errorHandler = new ErrorHandler();
|
||||
const updateCart = new UpdateCart(
|
||||
PayPalCommerceGateway.ajax.change_cart.endpoint,
|
||||
|
@ -32,6 +26,14 @@ class SingleProductBootstap {
|
|||
|
||||
renderer.render(configurator.configuration());
|
||||
}
|
||||
|
||||
shouldRender() {
|
||||
if (document.querySelector('form.cart') === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return document.querySelector(PayPalCommerceGateway.button.wrapper);
|
||||
}
|
||||
}
|
||||
|
||||
export default SingleProductBootstap;
|
Loading…
Add table
Add a link
Reference in a new issue