custom/plugins/PevrPayeverIntegration/src/Service/Setting/SettingsService.php line 97

Open in your IDE?
  1. <?php
  2. /**
  3.  * payever GmbH
  4.  *
  5.  * NOTICE OF LICENSE
  6.  *
  7.  * Permission is hereby granted, free of charge, to any person obtaining a copy
  8.  * of this software and associated documentation files (the "Software"), to deal
  9.  * in the Software without restriction, including without limitation the rights
  10.  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11.  * copies of the Software, and to permit persons to whom the Software is
  12.  * furnished to do so, subject to the following conditions:
  13.  *
  14.  * The above copyright notice and this permission notice shall be included in all
  15.  * copies or substantial portions of the Software.
  16.  *
  17.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18.  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19.  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  20.  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21.  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  22.  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  23.  * SOFTWARE.
  24.  *
  25.  * DISCLAIMER
  26.  *
  27.  * Do not edit or add to this file if you wish to upgrade payever Shopware package
  28.  * to newer versions in the future.
  29.  *
  30.  * @category    Payever
  31.  * @author      payever GmbH <service@payever.de>
  32.  * @copyright   Copyright (c) 2021 payever GmbH (http://www.payever.de)
  33.  * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
  34.  */
  35. declare(strict_types=1);
  36. namespace Payever\PayeverPayments\Service\Setting;
  37. use Payever\PayeverPayments\Service\Setting\Exception\PayeverSettingsInvalidException;
  38. use Shopware\Core\System\SystemConfig\SystemConfigService;
  39. class SettingsService implements SettingsServiceInterface
  40. {
  41.     private const SYSTEM_CONFIG_DOMAIN 'PevrPayeverIntegration.config.';
  42.     /**
  43.      * @var SystemConfigService
  44.      */
  45.     private $systemConfigService;
  46.     /**
  47.      * @var PayeverSettingGeneralStruct[]
  48.      */
  49.     private $configCache = [];
  50.     /**
  51.      * @param SystemConfigService $systemConfigService
  52.      */
  53.     public function __construct(SystemConfigService $systemConfigService)
  54.     {
  55.         $this->systemConfigService $systemConfigService;
  56.     }
  57.     /**
  58.      * @param string|null $salesChannelId
  59.      *
  60.      * @return PayeverSettingGeneralStruct
  61.      *
  62.      * @throws PayeverSettingsInvalidException
  63.      * @throws \Shopware\Core\Framework\DataAbstractionLayer\Exception\InconsistentCriteriaIdsException
  64.      * @throws \Shopware\Core\Framework\Uuid\Exception\InvalidUuidException
  65.      * @throws \Shopware\Core\System\SystemConfig\Exception\InvalidDomainException
  66.      */
  67.     public function getSettings(?string $salesChannelId null): PayeverSettingGeneralStruct
  68.     {
  69.         if (isset($this->configCache[$salesChannelId])) {
  70.             return $this->configCache[$salesChannelId];
  71.         }
  72.         $values $this->systemConfigService->getDomain(
  73.             self::SYSTEM_CONFIG_DOMAIN,
  74.             $salesChannelId,
  75.             true
  76.         );
  77.         $propertyValuePairs = [];
  78.         /** @var string $key */
  79.         foreach ($values as $key => $value) {
  80.             $property substr($keystrlen(self::SYSTEM_CONFIG_DOMAIN));
  81.             $propertyValuePairs[$property] = $value;
  82.         }
  83.         $settingsEntity = new PayeverSettingGeneralStruct();
  84.         $settingsEntity->assign($propertyValuePairs);
  85.         $settingsEntity->validate();
  86.         $this->configCache[$salesChannelId] = $settingsEntity;
  87.         return $settingsEntity;
  88.     }
  89.     /**
  90.      * @inheritDoc
  91.      */
  92.     public function updateSettings(array $settings, ?string $salesChannelId null): void
  93.     {
  94.         foreach ($settings as $key => $value) {
  95.             $this->systemConfigService->set(
  96.                 self::SYSTEM_CONFIG_DOMAIN $key,
  97.                 $value,
  98.                 $salesChannelId
  99.             );
  100.         }
  101.         $this->configCache = [];
  102.     }
  103.     /**
  104.      * Resets cache
  105.      */
  106.     public function resetCache()
  107.     {
  108.         $this->configCache = [];
  109.     }
  110. }