From 59a68fb604ad22adb232e01a1d4a291b7cffeb69 Mon Sep 17 00:00:00 2001
From: Pedro Silva
Date: Mon, 24 Jul 2023 17:09:45 +0100
Subject: [PATCH 1/3] Add sanitize woocommerce_widget_cart_is_hidden filter for
consistent values. Remove context restrictions to mini-cart paypal buttons.
---
modules/ppcp-button/resources/js/button.js | 17 +++++++------
.../ppcp-button/src/Assets/SmartButton.php | 24 +++++++++++++++++++
2 files changed, 32 insertions(+), 9 deletions(-)
diff --git a/modules/ppcp-button/resources/js/button.js b/modules/ppcp-button/resources/js/button.js
index 790030920..97fa91656 100644
--- a/modules/ppcp-button/resources/js/button.js
+++ b/modules/ppcp-button/resources/js/button.js
@@ -137,16 +137,15 @@ const bootstrap = () => {
};
const renderer = new Renderer(creditCardRenderer, PayPalCommerceGateway, onSmartButtonClick, onSmartButtonsInit);
const messageRenderer = new MessageRenderer(PayPalCommerceGateway.messages);
- if (context === 'mini-cart' || context === 'product') {
- if (PayPalCommerceGateway.mini_cart_buttons_enabled === '1') {
- const miniCartBootstrap = new MiniCartBootstap(
- PayPalCommerceGateway,
- renderer,
- errorHandler,
- );
- miniCartBootstrap.init();
- }
+ if (PayPalCommerceGateway.mini_cart_buttons_enabled === '1') {
+ const miniCartBootstrap = new MiniCartBootstap(
+ PayPalCommerceGateway,
+ renderer,
+ errorHandler,
+ );
+
+ miniCartBootstrap.init();
}
if (context === 'product' && PayPalCommerceGateway.single_product_buttons_enabled === '1') {
diff --git a/modules/ppcp-button/src/Assets/SmartButton.php b/modules/ppcp-button/src/Assets/SmartButton.php
index fded20a67..3e7af313b 100644
--- a/modules/ppcp-button/src/Assets/SmartButton.php
+++ b/modules/ppcp-button/src/Assets/SmartButton.php
@@ -372,6 +372,8 @@ class SmartButton implements SmartButtonInterface {
);
}
+ $this->sanitize_woocommerce_filters();
+
return true;
}
@@ -1522,4 +1524,26 @@ class SmartButton implements SmartButtonInterface {
return absint( $wp->query_vars['order-pay'] );
}
+
+ /**
+ * Sanitize woocommerce filter on unexpected states.
+ *
+ * @return void
+ */
+ private function sanitize_woocommerce_filters(): void {
+
+ // Sometimes external plugins like "woocommerce-one-page-checkout" set the $value to null.
+ // Here we also disable the mini-cart on cart-block and checkout-block pages where our buttons aren't supported yet.
+ add_filter( 'woocommerce_widget_cart_is_hidden', function ($value) {
+ if (null === $value) {
+ if ( is_product() ) {
+ return false;
+ }
+ return in_array($this->context(), array('cart', 'checkout', 'cart-block', 'checkout-block'));
+ }
+ return in_array($this->context(), array('cart-block', 'checkout-block')) ? true : $value;
+ }, 11);
+
+ }
+
}
From d2fc0d38286d5a9d92fe8a47e884e7b5f6cbd717 Mon Sep 17 00:00:00 2001
From: Pedro Silva
Date: Mon, 24 Jul 2023 17:24:34 +0100
Subject: [PATCH 2/3] Fix lint
---
.../ppcp-button/src/Assets/SmartButton.php | 28 ++++++++++++-------
1 file changed, 18 insertions(+), 10 deletions(-)
diff --git a/modules/ppcp-button/src/Assets/SmartButton.php b/modules/ppcp-button/src/Assets/SmartButton.php
index 3e7af313b..e0a42c7c9 100644
--- a/modules/ppcp-button/src/Assets/SmartButton.php
+++ b/modules/ppcp-button/src/Assets/SmartButton.php
@@ -1532,17 +1532,25 @@ class SmartButton implements SmartButtonInterface {
*/
private function sanitize_woocommerce_filters(): void {
- // Sometimes external plugins like "woocommerce-one-page-checkout" set the $value to null.
- // Here we also disable the mini-cart on cart-block and checkout-block pages where our buttons aren't supported yet.
- add_filter( 'woocommerce_widget_cart_is_hidden', function ($value) {
- if (null === $value) {
- if ( is_product() ) {
- return false;
+ add_filter(
+ 'woocommerce_widget_cart_is_hidden',
+ /**
+ * Sometimes external plugins like "woocommerce-one-page-checkout" set the $value to null, handle that case here.
+ * Here we also disable the mini-cart on cart-block and checkout-block pages where our buttons aren't supported yet.
+ *
+ * @psalm-suppress MissingClosureParamType
+ */
+ function ( $value ) {
+ if ( null === $value ) {
+ if ( is_product() ) {
+ return false;
+ }
+ return in_array( $this->context(), array( 'cart', 'checkout', 'cart-block', 'checkout-block' ), true );
}
- return in_array($this->context(), array('cart', 'checkout', 'cart-block', 'checkout-block'));
- }
- return in_array($this->context(), array('cart-block', 'checkout-block')) ? true : $value;
- }, 11);
+ return in_array( $this->context(), array( 'cart-block', 'checkout-block' ), true ) ? true : $value;
+ },
+ 11
+ );
}
From e81ed024bb0e5818c86c498de5792b2a9e58cc2f Mon Sep 17 00:00:00 2001
From: Pedro Silva
Date: Wed, 26 Jul 2023 10:31:39 +0100
Subject: [PATCH 3/3] Fix e2e testing
---
.github/workflows/e2e.yml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml
index c6496f58a..3731a1de4 100644
--- a/.github/workflows/e2e.yml
+++ b/.github/workflows/e2e.yml
@@ -15,7 +15,7 @@ jobs:
- uses: satackey/action-docker-layer-caching@v0.0.11
continue-on-error: true
- - uses: jonaseberle/github-action-setup-ddev@v1
+ - uses: ddev/github-action-setup-ddev@v1
with:
autostart: false