From 850bfb869a7be8fc3c2ac1934402892179038660 Mon Sep 17 00:00:00 2001
From: Philipp Stracker
Date: Wed, 12 Feb 2025 18:55:58 +0100
Subject: [PATCH 01/48] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Rename=20function=20?=
=?UTF-8?q?argument?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
modules/ppcp-settings/src/Data/OnboardingProfile.php | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/modules/ppcp-settings/src/Data/OnboardingProfile.php b/modules/ppcp-settings/src/Data/OnboardingProfile.php
index a2d8e6c36..ec2e40a0a 100644
--- a/modules/ppcp-settings/src/Data/OnboardingProfile.php
+++ b/modules/ppcp-settings/src/Data/OnboardingProfile.php
@@ -89,10 +89,10 @@ class OnboardingProfile extends AbstractDataModel {
/**
* Sets the 'completed' flag.
*
- * @param bool $step Whether the onboarding process has been completed.
+ * @param bool $state Whether the onboarding process has been completed.
*/
- public function set_completed( bool $step ) : void {
- $this->data['completed'] = $step;
+ public function set_completed( bool $state ) : void {
+ $this->data['completed'] = $state;
}
/**
From 34c67bb8d1224cef30b5d7d97b8075a96fc7cf09 Mon Sep 17 00:00:00 2001
From: Philipp Stracker
Date: Wed, 12 Feb 2025 18:56:37 +0100
Subject: [PATCH 02/48] =?UTF-8?q?=E2=9C=A8=20New=20onboarding=20flag=20for?=
=?UTF-8?q?=20=E2=80=9Csetup-done=E2=80=9D?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../src/Data/OnboardingProfile.php | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
diff --git a/modules/ppcp-settings/src/Data/OnboardingProfile.php b/modules/ppcp-settings/src/Data/OnboardingProfile.php
index ec2e40a0a..070d478c8 100644
--- a/modules/ppcp-settings/src/Data/OnboardingProfile.php
+++ b/modules/ppcp-settings/src/Data/OnboardingProfile.php
@@ -72,6 +72,7 @@ class OnboardingProfile extends AbstractDataModel {
'is_casual_seller' => null,
'are_optional_payment_methods_enabled' => null,
'products' => array(),
+ 'setup_done' => false,
);
}
@@ -166,4 +167,22 @@ class OnboardingProfile extends AbstractDataModel {
public function get_flags() : array {
return $this->flags;
}
+
+ /**
+ * Gets the 'setup_done' flag.
+ *
+ * @return bool
+ */
+ public function is_setup_done() : bool {
+ return (bool) $this->data['setup_done'];
+ }
+
+ /**
+ * Sets the 'setup_done' flag.
+ *
+ * @param bool $done Whether the onboarding process has been setup_done.
+ */
+ public function set_setup_done( bool $done ) : void {
+ $this->data['setup_done'] = $done;
+ }
}
From 0728f80281818599020fded6d46f548ce2274c59 Mon Sep 17 00:00:00 2001
From: Philipp Stracker
Date: Wed, 12 Feb 2025 21:06:47 +0100
Subject: [PATCH 03/48] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Refactor=20the=20set?=
=?UTF-8?q?tingsdata=20manager=20constructor?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
modules/ppcp-settings/services.php | 7 ++----
.../src/Service/SettingsDataManager.php | 22 ++++++++++++++-----
2 files changed, 19 insertions(+), 10 deletions(-)
diff --git a/modules/ppcp-settings/services.php b/modules/ppcp-settings/services.php
index e5ab98d74..9bc845589 100644
--- a/modules/ppcp-settings/services.php
+++ b/modules/ppcp-settings/services.php
@@ -249,17 +249,14 @@ return array(
return new DataSanitizer();
},
'settings.service.data-manager' => static function ( ContainerInterface $container ) : SettingsDataManager {
- $models = array(
+ return new SettingsDataManager(
$container->get( 'settings.data.onboarding' ),
$container->get( 'settings.data.general' ),
+ $container->get( 'settings.data.settings' ),
$container->get( 'settings.data.styling' ),
$container->get( 'settings.data.payment' ),
- $container->get( 'settings.data.settings' ),
$container->get( 'settings.data.todos' ),
- $container->get( 'settings.data.definition.todos' ),
);
-
- return new SettingsDataManager( $models );
},
'settings.ajax.switch_ui' => static function ( ContainerInterface $container ) : SwitchSettingsUiEndpoint {
return new SwitchSettingsUiEndpoint(
diff --git a/modules/ppcp-settings/src/Service/SettingsDataManager.php b/modules/ppcp-settings/src/Service/SettingsDataManager.php
index cb7aa6275..fd01a16ef 100644
--- a/modules/ppcp-settings/src/Service/SettingsDataManager.php
+++ b/modules/ppcp-settings/src/Service/SettingsDataManager.php
@@ -10,6 +10,7 @@ declare( strict_types = 1 );
namespace WooCommerce\PayPalCommerce\Settings\Service;
use WooCommerce\PayPalCommerce\Settings\Data\AbstractDataModel;
+use WooCommerce\PayPalCommerce\Settings\Data\OnboardingProfile;
/**
* Class SettingsDataManager
@@ -19,25 +20,36 @@ use WooCommerce\PayPalCommerce\Settings\Data\AbstractDataModel;
*/
class SettingsDataManager {
+ /**
+ * The onboarding profile data model.
+ *
+ * @var OnboardingProfile
+ */
+ private OnboardingProfile $onboarding_profile;
+
/**
* Stores a list of all AbstractDataModel instances that are managed by
* this service.
*
* @var AbstractDataModel[]
*/
- private array $models = array();
+ private array $purgeable_models = array();
/**
* Constructor.
*
- * @param array $data_models List of AbstractDataModel instances.
+ * @param OnboardingProfile $onboarding_profile The onboarding profile model.
+ * @param array ...$data_models List of additional data models to reset.
*/
- public function __construct( array $data_models ) {
+ public function __construct( OnboardingProfile $onboarding_profile, ...$data_models ) {
foreach ( $data_models as $data_model ) {
if ( $data_model instanceof AbstractDataModel ) {
- $this->models[] = $data_model;
+ $this->purgeable_models[] = $data_model;
}
}
+
+ $this->purgeable_models[] = $onboarding_profile;
+ $this->onboarding_profile = $onboarding_profile;
}
/**
@@ -52,7 +64,7 @@ class SettingsDataManager {
*/
do_action( 'woocommerce_paypal_payments_reset_settings' );
- foreach ( $this->models as $model ) {
+ foreach ( $this->purgeable_models as $model ) {
$model->purge();
}
From cda49d87e26244a0c0dbba7a9bbe0f6e5da9b493 Mon Sep 17 00:00:00 2001
From: Philipp Stracker
Date: Wed, 12 Feb 2025 21:07:56 +0100
Subject: [PATCH 04/48] =?UTF-8?q?=E2=9C=A8=20New=20DTO=20to=20define=20plu?=
=?UTF-8?q?gin=20setup=20configuration?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../src/DTO/ConfigurationFlagsDTO.php | 47 +++++++++++++++++++
1 file changed, 47 insertions(+)
create mode 100644 modules/ppcp-settings/src/DTO/ConfigurationFlagsDTO.php
diff --git a/modules/ppcp-settings/src/DTO/ConfigurationFlagsDTO.php b/modules/ppcp-settings/src/DTO/ConfigurationFlagsDTO.php
new file mode 100644
index 000000000..4f00ff405
--- /dev/null
+++ b/modules/ppcp-settings/src/DTO/ConfigurationFlagsDTO.php
@@ -0,0 +1,47 @@
+
Date: Wed, 12 Feb 2025 21:08:37 +0100
Subject: [PATCH 05/48] =?UTF-8?q?=E2=9C=A8=20Add=20a=20plugin-config=20met?=
=?UTF-8?q?hod=20to=20the=20data=20manager?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../src/Service/SettingsDataManager.php | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/modules/ppcp-settings/src/Service/SettingsDataManager.php b/modules/ppcp-settings/src/Service/SettingsDataManager.php
index fd01a16ef..465a4f195 100644
--- a/modules/ppcp-settings/src/Service/SettingsDataManager.php
+++ b/modules/ppcp-settings/src/Service/SettingsDataManager.php
@@ -11,6 +11,7 @@ namespace WooCommerce\PayPalCommerce\Settings\Service;
use WooCommerce\PayPalCommerce\Settings\Data\AbstractDataModel;
use WooCommerce\PayPalCommerce\Settings\Data\OnboardingProfile;
+use WooCommerce\PayPalCommerce\Settings\DTO\ConfigurationFlagsDTO;
/**
* Class SettingsDataManager
@@ -71,4 +72,16 @@ class SettingsDataManager {
// Clear any caches.
wp_cache_flush();
}
+
+ /**
+ * Applies a default configuration to the plugin.
+ *
+ * @param ConfigurationFlagsDTO $flags The configuration flags.
+ * @return void
+ */
+ public function apply_configuration( ConfigurationFlagsDTO $flags ) : void {
+ // Onboarding stuff...
+
+ $this->onboarding_profile->set_setup_done( true );
+ }
}
From 275c28bfa3f6ddd0b8a5d2ab3c351a772bca17e3 Mon Sep 17 00:00:00 2001
From: Philipp Stracker
Date: Wed, 12 Feb 2025 21:14:26 +0100
Subject: [PATCH 06/48] =?UTF-8?q?=F0=9F=91=94=20Apply=20plugin=20configura?=
=?UTF-8?q?tion=20after=20authentication?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../src/Service/SettingsDataManager.php | 1 +
modules/ppcp-settings/src/SettingsModule.php | 18 ++++++++++++++++++
2 files changed, 19 insertions(+)
diff --git a/modules/ppcp-settings/src/Service/SettingsDataManager.php b/modules/ppcp-settings/src/Service/SettingsDataManager.php
index 465a4f195..20c6c7533 100644
--- a/modules/ppcp-settings/src/Service/SettingsDataManager.php
+++ b/modules/ppcp-settings/src/Service/SettingsDataManager.php
@@ -83,5 +83,6 @@ class SettingsDataManager {
// Onboarding stuff...
$this->onboarding_profile->set_setup_done( true );
+ $this->onboarding_profile->save();
}
}
diff --git a/modules/ppcp-settings/src/SettingsModule.php b/modules/ppcp-settings/src/SettingsModule.php
index 2035011d6..38e51fc1b 100644
--- a/modules/ppcp-settings/src/SettingsModule.php
+++ b/modules/ppcp-settings/src/SettingsModule.php
@@ -36,6 +36,8 @@ use WooCommerce\PayPalCommerce\WcGateway\Gateway\OXXO\OXXO;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice\PayUponInvoiceGateway;
use WooCommerce\PayPalCommerce\WcGateway\Helper\DCCProductStatus;
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
+use WooCommerce\PayPalCommerce\Settings\Service\SettingsDataManager;
+use WooCommerce\PayPalCommerce\Settings\DTO\ConfigurationFlagsDTO;
/**
* Class SettingsModule
@@ -288,6 +290,22 @@ class SettingsModule implements ServiceModule, ExecutableModule {
$onboarding_profile->set_completed( true );
$onboarding_profile->save();
+
+ // If the initial plugin configuration was not applied yet, do it now.
+ if ( ! $onboarding_profile->is_setup_done() ) {
+ $data_manager = $container->get( 'settings.service.data-manager' );
+ assert( $data_manager instanceof SettingsDataManager );
+
+ $flags = new ConfigurationFlagsDTO();
+
+ // TODO: Dummy values, use real values!
+ $flags->country_code = 'US';
+ $flags->is_business_seller = true;
+ $flags->use_card_payments = true;
+ $flags->use_subscriptions = true;
+
+ $data_manager->apply_configuration( $flags );
+ }
}
);
From f8d5213b16b69396b29168ea0572ec6e0a4aa0cd Mon Sep 17 00:00:00 2001
From: Philipp Stracker
Date: Wed, 12 Feb 2025 21:14:52 +0100
Subject: [PATCH 07/48] =?UTF-8?q?=F0=9F=8E=A8=20Apply=20phpcs=20styles?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
modules/ppcp-settings/src/SettingsModule.php | 20 ++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)
diff --git a/modules/ppcp-settings/src/SettingsModule.php b/modules/ppcp-settings/src/SettingsModule.php
index 38e51fc1b..52278b84e 100644
--- a/modules/ppcp-settings/src/SettingsModule.php
+++ b/modules/ppcp-settings/src/SettingsModule.php
@@ -124,7 +124,7 @@ class SettingsModule implements ServiceModule, ExecutableModule {
add_action(
'woocommerce_paypal_payments_gateway_migrate_on_update',
- static fn () => ! get_option( SwitchSettingsUiEndpoint::OPTION_NAME_SHOULD_USE_OLD_UI )
+ static fn() => ! get_option( SwitchSettingsUiEndpoint::OPTION_NAME_SHOULD_USE_OLD_UI )
&& update_option( SwitchSettingsUiEndpoint::OPTION_NAME_SHOULD_USE_OLD_UI, 'yes' )
);
@@ -311,7 +311,7 @@ class SettingsModule implements ServiceModule, ExecutableModule {
add_filter(
'woocommerce_paypal_payments_payment_methods',
- function( array $payment_methods ) use ( $container ) : array {
+ function ( array $payment_methods ) use ( $container ) : array {
$all_payment_methods = $payment_methods;
$dcc_product_status = $container->get( 'wcgateway.helper.dcc-product-status' );
@@ -380,7 +380,7 @@ class SettingsModule implements ServiceModule, ExecutableModule {
*
* @psalm-suppress MissingClosureParamType
*/
- static function ( $methods ) use ( $container ): array {
+ static function ( $methods ) use ( $container ) : array {
if ( ! is_array( $methods ) ) {
return $methods;
}
@@ -408,7 +408,7 @@ class SettingsModule implements ServiceModule, ExecutableModule {
add_filter(
'woocommerce_paypal_payments_gateway_title',
- function( string $title, WC_Payment_Gateway $gateway ) {
+ function ( string $title, WC_Payment_Gateway $gateway ) {
return $gateway->get_option( 'title', $title );
},
10,
@@ -416,7 +416,7 @@ class SettingsModule implements ServiceModule, ExecutableModule {
);
add_filter(
'woocommerce_paypal_payments_gateway_description',
- function( string $description, WC_Payment_Gateway $gateway ) {
+ function ( string $description, WC_Payment_Gateway $gateway ) {
return $gateway->get_option( 'description', $description );
},
10,
@@ -427,7 +427,7 @@ class SettingsModule implements ServiceModule, ExecutableModule {
add_filter(
'woocommerce_paypal_payments_credit_card_gateway_form_fields',
- function( array $form_fields ) {
+ function ( array $form_fields ) {
$form_fields['enabled'] = array(
'title' => __( 'Enable/Disable', 'woocommerce-paypal-payments' ),
'type' => 'checkbox',
@@ -444,7 +444,7 @@ class SettingsModule implements ServiceModule, ExecutableModule {
add_filter(
'woocommerce_paypal_payments_credit_card_gateway_title',
- function( string $title, WC_Payment_Gateway $gateway ) {
+ function ( string $title, WC_Payment_Gateway $gateway ) {
return $gateway->get_option( 'title', $title );
},
10,
@@ -452,7 +452,7 @@ class SettingsModule implements ServiceModule, ExecutableModule {
);
add_filter(
'woocommerce_paypal_payments_credit_card_gateway_description',
- function( string $description, WC_Payment_Gateway $gateway ) {
+ function ( string $description, WC_Payment_Gateway $gateway ) {
return $gateway->get_option( 'description', $description );
},
10,
@@ -462,7 +462,7 @@ class SettingsModule implements ServiceModule, ExecutableModule {
add_filter( 'woocommerce_paypal_payments_axo_gateway_should_update_enabled', '__return_false' );
add_filter(
'woocommerce_paypal_payments_axo_gateway_title',
- function( string $title, WC_Payment_Gateway $gateway ) {
+ function ( string $title, WC_Payment_Gateway $gateway ) {
return $gateway->get_option( 'title', $title );
},
10,
@@ -470,7 +470,7 @@ class SettingsModule implements ServiceModule, ExecutableModule {
);
add_filter(
'woocommerce_paypal_payments_axo_gateway_description',
- function( string $description, WC_Payment_Gateway $gateway ) {
+ function ( string $description, WC_Payment_Gateway $gateway ) {
return $gateway->get_option( 'description', $description );
},
10,
From 7a5ac3cabac46c9c7d1075a99ed6fc4686855945 Mon Sep 17 00:00:00 2001
From: Philipp Stracker
Date: Thu, 13 Feb 2025 14:27:05 +0100
Subject: [PATCH 08/48] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Move=20detection=20o?=
=?UTF-8?q?f=20=E2=80=9Cnew=20merchant=E2=80=9D=20into=20manager?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../src/Service/SettingsDataManager.php | 28 +++++++++++++++++--
modules/ppcp-settings/src/SettingsModule.php | 22 +++++++--------
2 files changed, 35 insertions(+), 15 deletions(-)
diff --git a/modules/ppcp-settings/src/Service/SettingsDataManager.php b/modules/ppcp-settings/src/Service/SettingsDataManager.php
index 20c6c7533..5d0e4153c 100644
--- a/modules/ppcp-settings/src/Service/SettingsDataManager.php
+++ b/modules/ppcp-settings/src/Service/SettingsDataManager.php
@@ -74,15 +74,37 @@ class SettingsDataManager {
}
/**
- * Applies a default configuration to the plugin.
+ * Applies a default configuration to the plugin for a new merchant.
+ *
+ * This method checks the onboarding "setup_done" flag to determine if
+ * the defaults should be applied. At the end of this method, the
+ * "setup_done" flag is set, so future calls to the method have no effect.
*
* @param ConfigurationFlagsDTO $flags The configuration flags.
* @return void
*/
- public function apply_configuration( ConfigurationFlagsDTO $flags ) : void {
- // Onboarding stuff...
+ public function set_defaults_for_new_merchant( ConfigurationFlagsDTO $flags ) : void {
+ if ( $this->onboarding_profile->is_setup_done() ) {
+ return;
+ }
+
+ $this->apply_configuration( $flags );
$this->onboarding_profile->set_setup_done( true );
$this->onboarding_profile->save();
}
+
+ /**
+ * Applies a default configuration to the plugin, without any condition.
+ *
+ * @param ConfigurationFlagsDTO $flags The configuration flags.
+ * @return void
+ */
+ protected function apply_configuration( ConfigurationFlagsDTO $flags ) : void {
+ // Apply defaults for the "Payment Methods" tab.
+
+ // Apply defaults for the "Settings" tab.
+
+ // Assign defaults for the "Styling" tab.
+ }
}
diff --git a/modules/ppcp-settings/src/SettingsModule.php b/modules/ppcp-settings/src/SettingsModule.php
index 52278b84e..50bd9e294 100644
--- a/modules/ppcp-settings/src/SettingsModule.php
+++ b/modules/ppcp-settings/src/SettingsModule.php
@@ -291,21 +291,19 @@ class SettingsModule implements ServiceModule, ExecutableModule {
$onboarding_profile->set_completed( true );
$onboarding_profile->save();
- // If the initial plugin configuration was not applied yet, do it now.
- if ( ! $onboarding_profile->is_setup_done() ) {
- $data_manager = $container->get( 'settings.service.data-manager' );
- assert( $data_manager instanceof SettingsDataManager );
+ // Try to apply a default configuration for the current store.
+ $data_manager = $container->get( 'settings.service.data-manager' );
+ assert( $data_manager instanceof SettingsDataManager );
- $flags = new ConfigurationFlagsDTO();
+ $flags = new ConfigurationFlagsDTO();
- // TODO: Dummy values, use real values!
- $flags->country_code = 'US';
- $flags->is_business_seller = true;
- $flags->use_card_payments = true;
- $flags->use_subscriptions = true;
+ // TODO: Dummy values, use real values!
+ $flags->country_code = 'US';
+ $flags->is_business_seller = true;
+ $flags->use_card_payments = true;
+ $flags->use_subscriptions = true;
- $data_manager->apply_configuration( $flags );
- }
+ $data_manager->set_defaults_for_new_merchant( $flags );
}
);
From 8c411c196941346cd82e8e9bb1c74f1a831ea9a3 Mon Sep 17 00:00:00 2001
From: Philipp Stracker
Date: Thu, 13 Feb 2025 14:27:59 +0100
Subject: [PATCH 09/48] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Minor=20renaming=20o?=
=?UTF-8?q?f=20attributes?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../src/Service/SettingsDataManager.php | 16 ++++++++++++----
1 file changed, 12 insertions(+), 4 deletions(-)
diff --git a/modules/ppcp-settings/src/Service/SettingsDataManager.php b/modules/ppcp-settings/src/Service/SettingsDataManager.php
index 5d0e4153c..6dc954728 100644
--- a/modules/ppcp-settings/src/Service/SettingsDataManager.php
+++ b/modules/ppcp-settings/src/Service/SettingsDataManager.php
@@ -34,7 +34,7 @@ class SettingsDataManager {
*
* @var AbstractDataModel[]
*/
- private array $purgeable_models = array();
+ private array $models_to_reset = array();
/**
* Constructor.
@@ -44,12 +44,20 @@ class SettingsDataManager {
*/
public function __construct( OnboardingProfile $onboarding_profile, ...$data_models ) {
foreach ( $data_models as $data_model ) {
+ /**
+ * An instance extracted from the spread operator. We only process
+ * AbstractDataModel instances.
+ *
+ * @var mixed|AbstractDataModel $data_model
+ */
+
if ( $data_model instanceof AbstractDataModel ) {
- $this->purgeable_models[] = $data_model;
+ $this->models_to_reset[] = $data_model;
}
}
- $this->purgeable_models[] = $onboarding_profile;
+ $this->models_to_reset[] = $onboarding_profile;
+
$this->onboarding_profile = $onboarding_profile;
}
@@ -65,7 +73,7 @@ class SettingsDataManager {
*/
do_action( 'woocommerce_paypal_payments_reset_settings' );
- foreach ( $this->purgeable_models as $model ) {
+ foreach ( $this->models_to_reset as $model ) {
$model->purge();
}
From 769234ca157c7ea02ffd20978e79c497e0f9918b Mon Sep 17 00:00:00 2001
From: Philipp Stracker
Date: Thu, 13 Feb 2025 14:43:54 +0100
Subject: [PATCH 10/48] =?UTF-8?q?=E2=9C=A8=20Apply=20styling=20config=20af?=
=?UTF-8?q?ter=20onboarding?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../src/Service/SettingsDataManager.php | 71 ++++++++++++++++++-
1 file changed, 70 insertions(+), 1 deletion(-)
diff --git a/modules/ppcp-settings/src/Service/SettingsDataManager.php b/modules/ppcp-settings/src/Service/SettingsDataManager.php
index 6dc954728..b47529337 100644
--- a/modules/ppcp-settings/src/Service/SettingsDataManager.php
+++ b/modules/ppcp-settings/src/Service/SettingsDataManager.php
@@ -12,6 +12,13 @@ namespace WooCommerce\PayPalCommerce\Settings\Service;
use WooCommerce\PayPalCommerce\Settings\Data\AbstractDataModel;
use WooCommerce\PayPalCommerce\Settings\Data\OnboardingProfile;
use WooCommerce\PayPalCommerce\Settings\DTO\ConfigurationFlagsDTO;
+use WooCommerce\PayPalCommerce\Settings\DTO\LocationStylingDTO;
+use WooCommerce\PayPalCommerce\Googlepay\GooglePayGateway;
+use WooCommerce\PayPalCommerce\Applepay\ApplePayGateway;
+use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
+use WooCommerce\PayPalCommerce\Settings\Data\StylingSettings;
+use WooCommerce\PayPalCommerce\Settings\Data\GeneralSettings;
+use WooCommerce\PayPalCommerce\Settings\Data\SettingsModel;
/**
* Class SettingsDataManager
@@ -28,6 +35,13 @@ class SettingsDataManager {
*/
private OnboardingProfile $onboarding_profile;
+ /**
+ * Data model that handles button styling on the front end.
+ *
+ * @var StylingSettings
+ */
+ private StylingSettings $styling_settings;
+
/**
* Stores a list of all AbstractDataModel instances that are managed by
* this service.
@@ -40,9 +54,18 @@ class SettingsDataManager {
* Constructor.
*
* @param OnboardingProfile $onboarding_profile The onboarding profile model.
+ * @param GeneralSettings $general_settings The general settings model.
+ * @param SettingsModel $settings_model The settings model.
+ * @param StylingSettings $styling_settings The styling settings model.
* @param array ...$data_models List of additional data models to reset.
*/
- public function __construct( OnboardingProfile $onboarding_profile, ...$data_models ) {
+ public function __construct(
+ OnboardingProfile $onboarding_profile,
+ GeneralSettings $general_settings,
+ SettingsModel $settings_model,
+ StylingSettings $styling_settings,
+ ...$data_models
+ ) {
foreach ( $data_models as $data_model ) {
/**
* An instance extracted from the spread operator. We only process
@@ -57,8 +80,12 @@ class SettingsDataManager {
}
$this->models_to_reset[] = $onboarding_profile;
+ $this->models_to_reset[] = $general_settings;
+ $this->models_to_reset[] = $settings_model;
+ $this->models_to_reset[] = $styling_settings;
$this->onboarding_profile = $onboarding_profile;
+ $this->styling_settings = $styling_settings;
}
/**
@@ -114,5 +141,47 @@ class SettingsDataManager {
// Apply defaults for the "Settings" tab.
// Assign defaults for the "Styling" tab.
+ $location_styles = $this->get_location_styles( $flags );
+ $this->styling_settings->from_array( $location_styles );
+ $this->styling_settings->save();
+ }
+
+ /**
+ * Builds an array of styling details that should be applied for the shop.
+ *
+ * @param ConfigurationFlagsDTO $flags Shop configuration flags.
+ * @return LocationStylingDTO[] A set of styling details.
+ */
+ protected function get_location_styles( ConfigurationFlagsDTO $flags ) : array {
+ $methods_full = array(
+ PayPalGateway::ID,
+ 'venmo',
+ 'pay-later',
+ ApplePayGateway::ID,
+ GooglePayGateway::ID,
+ );
+
+ $methods_own = array(
+ PayPalGateway::ID,
+ 'venmo',
+ 'pay-later',
+ );
+
+ return array(
+ // Cart: Enabled, display PayPal, Venmo, Pay Later, Google Pay, Apple Pay.
+ 'cart' => new LocationStylingDTO( 'cart', true, $methods_full ),
+
+ // Classic Checkout: Display PayPal, Venmo, Pay Later, Google Pay, Apple Pay.
+ 'classic_checkout' => new LocationStylingDTO( 'classic_checkout', true, $methods_full ),
+
+ // Express Checkout: Display PayPal, Venmo, Pay Later, Google Pay, Apple Pay.
+ 'express_checkout' => new LocationStylingDTO( 'express_checkout', true, $methods_full ),
+
+ // Mini Cart: Display PayPal, Venmo, Pay Later, Google Pay, Apple Pay.
+ 'mini_cart' => new LocationStylingDTO( 'mini_cart', true, $methods_full ),
+
+ // Product Page: Display PayPal, Venmo, Pay Later.
+ 'product' => new LocationStylingDTO( 'product', true, $methods_own ),
+ );
}
}
From f7b2f97b891634e9d5dcc1cbaf325cfee5480a64 Mon Sep 17 00:00:00 2001
From: Philipp Stracker
Date: Thu, 13 Feb 2025 15:08:50 +0100
Subject: [PATCH 11/48] =?UTF-8?q?=F0=9F=92=84=20Improve=20visual=20hint=20?=
=?UTF-8?q?for=20settings-reset=20toggle?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../resources/css/components/screens/_modals.scss | 10 ++++++++--
.../Components/Settings/Parts/DisconnectButton.js | 2 +-
2 files changed, 9 insertions(+), 3 deletions(-)
diff --git a/modules/ppcp-settings/resources/css/components/screens/_modals.scss b/modules/ppcp-settings/resources/css/components/screens/_modals.scss
index fee98d538..5dbdf7652 100644
--- a/modules/ppcp-settings/resources/css/components/screens/_modals.scss
+++ b/modules/ppcp-settings/resources/css/components/screens/_modals.scss
@@ -2,12 +2,18 @@
* Modal for disconnecting the merchant from the current PayPal account.
*/
.ppcp--modal-disconnect {
- .ppcp--toggle-danger {
- --wp-components-color-accent: #cc1818
+ .ppcp--toggle-danger .components-form-toggle {
+ &.is-checked {
+ --wp-components-color-accent: #cc1818;
+ }
}
.ppcp--action-buttons {
text-align: right;
margin-top: 32px;
+
+ .components-button {
+ transition: background 0.3s;
+ }
}
}
diff --git a/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Settings/Parts/DisconnectButton.js b/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Settings/Parts/DisconnectButton.js
index 8e5fbe9d6..48fd6c226 100644
--- a/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Settings/Parts/DisconnectButton.js
+++ b/modules/ppcp-settings/resources/js/Components/Screens/Settings/Components/Settings/Parts/DisconnectButton.js
@@ -78,7 +78,7 @@ const DisconnectButton = () => {