custom/plugins/EasyCreditRatenkauf/src/Setting/Service/SettingsService.php line 47

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. /*
  3.  * (c) NETZKOLLEKTIV GmbH <kontakt@netzkollektiv.com>
  4.  * For the full copyright and license information, please view the LICENSE
  5.  * file that was distributed with this source code.
  6.  */
  7. namespace Netzkollektiv\EasyCredit\Setting\Service;
  8. use Netzkollektiv\EasyCredit\Setting\SettingStruct;
  9. use Netzkollektiv\EasyCredit\Setting\SettingStructValidator;
  10. use Shopware\Core\System\SystemConfig\SystemConfigService;
  11. class SettingsService implements SettingsServiceInterface
  12. {
  13.     public const SYSTEM_CONFIG_DOMAIN 'EasyCreditRatenkauf.config.';
  14.     private $systemConfigService;
  15.     private array $settingsCache;
  16.     public function __construct(SystemConfigService $systemConfigService)
  17.     {
  18.         $this->systemConfigService $systemConfigService;
  19.     }
  20.     public function getSettings(?string $salesChannelId nullbool $validate true): SettingStruct
  21.     {
  22.         if (!isset($this->settingsCache[$salesChannelId])) {
  23.             $values $this->systemConfigService->getDomain(
  24.                 self::SYSTEM_CONFIG_DOMAIN,
  25.                 $salesChannelId,
  26.                 true
  27.             );
  28.             $propertyValuePairs = [];
  29.             foreach ($values as $key => $value) {
  30.                 $property = (string) \mb_substr($key\mb_strlen(self::SYSTEM_CONFIG_DOMAIN));
  31.                 if ($property === '') {
  32.                     continue;
  33.                 }
  34.                 $propertyValuePairs[$property] = $value;
  35.             }
  36.             $settingsEntity = new SettingStruct();
  37.             $settingsEntity->assign($propertyValuePairs);
  38.             $this->settingsCache[$salesChannelId] = $settingsEntity;
  39.         }
  40.         $settingsEntity $this->settingsCache[$salesChannelId];
  41.         if ($validate) {
  42.             SettingStructValidator::validate($settingsEntity);
  43.         }
  44.         return $settingsEntity;
  45.     }
  46.     public function updateSettings(array $settings, ?string $salesChannelId null): void
  47.     {
  48.         unset($this->settingsCache[$salesChannelId]);
  49.         foreach ($settings as $key => $value) {
  50.             $this->systemConfigService->set(
  51.                 self::SYSTEM_CONFIG_DOMAIN $key,
  52.                 $value,
  53.                 $salesChannelId
  54.             );
  55.         }
  56.     }
  57. }