do only overwrite settings, which can be altered in current screen

This commit is contained in:
David Remer 2020-07-10 08:41:23 +03:00
parent bf1737a22e
commit 8fef1ec612
2 changed files with 9 additions and 2 deletions

View file

@ -62,11 +62,12 @@ return [
$settings = $container->get('wcgateway.settings');
$fields = $container->get('wcgateway.settings.fields');
$webhookRegistrar = $container->get('webhook.registrar');
$state = $container->get('onboarding.state');
global $wpdb;
$cacheFactory = new CachePoolFactory($wpdb);
$pool = $cacheFactory->createCachePool('ppcp-token');
return new SettingsListener($settings, $fields, $webhookRegistrar, $pool);
return new SettingsListener($settings, $fields, $webhookRegistrar, $pool, $state);
},
'wcgateway.order-processor' => static function (ContainerInterface $container): OrderProcessor {

View file

@ -17,17 +17,20 @@ class SettingsListener
private $settingFields;
private $webhookRegistrar;
private $cache;
private $state;
public function __construct(
Settings $settings,
array $settingFields,
WebhookRegistrar $webhookRegistrar,
CacheInterface $cache
CacheInterface $cache,
State $state
) {
$this->settings = $settings;
$this->settingFields = $settingFields;
$this->webhookRegistrar = $webhookRegistrar;
$this->cache = $cache;
$this->state = $state;
}
public function listen()
@ -73,6 +76,9 @@ class SettingsListener
{
$settings = [];
foreach ($this->settingFields as $key => $config) {
if (! in_array($this->state->currentState(), $config['screens'], true)) {
continue;
}
switch ($config['type']) {
case 'checkbox':
$settings[$key] = isset($rawData[$key]);