From 40bd3f1d5ca3f74d4ebd76b011f10191ea7f9b99 Mon Sep 17 00:00:00 2001 From: Pedro Silva Date: Mon, 20 Nov 2023 10:43:09 +0000 Subject: [PATCH] Refactor button and paylater messaging default locations. --- modules/ppcp-wc-gateway/services.php | 18 +++++++--- .../Settings/Fields/pay-later-tab-fields.php | 4 +-- .../ppcp-wc-gateway/src/Settings/Settings.php | 33 ++++++++++++++++--- 3 files changed, 43 insertions(+), 12 deletions(-) diff --git a/modules/ppcp-wc-gateway/services.php b/modules/ppcp-wc-gateway/services.php index 68d4ed172..8a0348a80 100644 --- a/modules/ppcp-wc-gateway/services.php +++ b/modules/ppcp-wc-gateway/services.php @@ -209,7 +209,9 @@ return array( static function ( ContainerInterface $container ): Settings { return new Settings( $container->get( 'wcgateway.button.default-locations' ), - $container->get( 'wcgateway.settings.dcc-gateway-title.default' ) + $container->get( 'wcgateway.settings.dcc-gateway-title.default' ), + $container->get( 'wcgateway.settings.pay-later.default-button-locations' ), + $container->get( 'wcgateway.settings.pay-later.default-messaging-locations' ) ); } ), @@ -1360,6 +1362,11 @@ return array( 'mini-cart' => 'Mini Cart', ); }, + 'wcgateway.button.default-locations' => static function( ContainerInterface $container ): array { + $button_locations = $container->get( 'wcgateway.button.locations' ); + unset( $button_locations['mini-cart'] ); + return array_keys( $button_locations ); + }, 'wcgateway.settings.pay-later.messaging-locations' => static function( ContainerInterface $container ): array { $button_locations = $container->get( 'wcgateway.button.locations' ); unset( $button_locations['mini-cart'] ); @@ -1371,10 +1378,8 @@ return array( ) ); }, - 'wcgateway.button.default-locations' => static function( ContainerInterface $container ): array { - $button_locations = $container->get( 'wcgateway.button.locations' ); - unset( $button_locations['mini-cart'] ); - return array_keys( $button_locations ); + 'wcgateway.settings.pay-later.default-messaging-locations' => static function( ContainerInterface $container ): array { + return array_keys( $container->get( 'wcgateway.settings.pay-later.messaging-locations' ) ); }, 'wcgateway.settings.pay-later.button-locations' => static function( ContainerInterface $container ): array { $settings = $container->get( 'wcgateway.settings' ); @@ -1386,6 +1391,9 @@ return array( return array_intersect_key( $button_locations, array_flip( $smart_button_selected_locations ) ); }, + 'wcgateway.settings.pay-later.default-button-locations' => static function( ContainerInterface $container ): array { + return $container->get( 'wcgateway.button.default-locations' ); + }, 'wcgateway.ppcp-gateways' => static function ( ContainerInterface $container ): array { return array( PayPalGateway::ID, diff --git a/modules/ppcp-wc-gateway/src/Settings/Fields/pay-later-tab-fields.php b/modules/ppcp-wc-gateway/src/Settings/Fields/pay-later-tab-fields.php index 99a3fd3f0..4fc6635f7 100644 --- a/modules/ppcp-wc-gateway/src/Settings/Fields/pay-later-tab-fields.php +++ b/modules/ppcp-wc-gateway/src/Settings/Fields/pay-later-tab-fields.php @@ -73,7 +73,7 @@ return function ( ContainerInterface $container, array $fields ): array { 'type' => 'ppcp-multiselect', 'class' => array(), 'input_class' => array( 'wc-enhanced-select' ), - 'default' => $container->get( 'wcgateway.button.default-locations' ), + 'default' => $container->get( 'wcgateway.settings.pay-later.default-button-locations' ), 'desc_tip' => false, 'description' => __( 'Select where the Pay Later button should be displayed.', 'woocommerce-paypal-payments' ), 'options' => $container->get( 'wcgateway.settings.pay-later.button-locations' ), @@ -119,7 +119,7 @@ return function ( ContainerInterface $container, array $fields ): array { 'type' => 'ppcp-multiselect', 'class' => array(), 'input_class' => array( 'wc-enhanced-select' ), - 'default' => $container->get( 'wcgateway.button.default-locations' ), + 'default' => $container->get( 'wcgateway.settings.pay-later.default-messaging-locations' ), 'desc_tip' => false, 'description' => __( 'Select where the Pay Later messaging should be displayed.', 'woocommerce-paypal-payments' ), 'options' => $container->get( 'wcgateway.settings.pay-later.messaging-locations' ), diff --git a/modules/ppcp-wc-gateway/src/Settings/Settings.php b/modules/ppcp-wc-gateway/src/Settings/Settings.php index 9abca804d..9ba1529c2 100644 --- a/modules/ppcp-wc-gateway/src/Settings/Settings.php +++ b/modules/ppcp-wc-gateway/src/Settings/Settings.php @@ -35,6 +35,20 @@ class Settings implements ContainerInterface { */ protected $default_button_locations; + /** + * The list of selected default pay later button locations. + * + * @var string[] + */ + protected $default_pay_later_button_locations; + + /** + * The list of selected default pay later messaging locations. + * + * @var string[] + */ + protected $default_pay_later_messaging_locations; + /** * The default ACDC gateway title. * @@ -47,10 +61,19 @@ class Settings implements ContainerInterface { * * @param string[] $default_button_locations The list of selected default button locations. * @param string $default_dcc_gateway_title The default ACDC gateway title. + * @param string[] $default_pay_later_button_locations The list of selected default pay later button locations. + * @param string[] $default_pay_later_messaging_locations The list of selected default pay later messaging locations. */ - public function __construct( array $default_button_locations, string $default_dcc_gateway_title ) { - $this->default_button_locations = $default_button_locations; - $this->default_dcc_gateway_title = $default_dcc_gateway_title; + public function __construct( + array $default_button_locations, + string $default_dcc_gateway_title, + array $default_pay_later_button_locations, + array $default_pay_later_messaging_locations + ) { + $this->default_button_locations = $default_button_locations; + $this->default_dcc_gateway_title = $default_dcc_gateway_title; + $this->default_pay_later_button_locations = $default_pay_later_button_locations; + $this->default_pay_later_messaging_locations = $default_pay_later_messaging_locations; } /** @@ -122,8 +145,8 @@ class Settings implements ContainerInterface { 'smart_button_enable_styling_per_location' => true, 'pay_later_messaging_enabled' => true, 'pay_later_button_enabled' => true, - 'pay_later_button_locations' => $this->default_button_locations, - 'pay_later_messaging_locations' => $this->default_button_locations, + 'pay_later_button_locations' => $this->default_pay_later_button_locations, + 'pay_later_messaging_locations' => $this->default_pay_later_messaging_locations, 'brand_name' => get_bloginfo( 'name' ), 'dcc_gateway_title' => $this->default_dcc_gateway_title, 'dcc_gateway_description' => __(