custom/plugins/NimbitsPriceOnRequestNext/src/Setting/Service/SettingService.php line 52

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. /**
  3.  * (c) shopware AG <info@shopware.com>
  4.  *
  5.  * For the full copyright and license information, please view the LICENSE
  6.  * file that was distributed with this source code.
  7.  */
  8. namespace Nimbits\NimbitsPriceOnRequestNext\Setting\Service;
  9. use Shopware\Core\Framework\Struct\StructCollection;
  10. use Shopware\Core\System\SystemConfig\SystemConfigService;
  11. class SettingService
  12. {
  13.     public const SYSTEM_CONFIG_DOMAIN = 'NimbitsPriceOnRequestNext.config.';
  14.     /**
  15.      * @var SystemConfigService
  16.      */
  17.     private $systemConfigService;
  18.     public function __construct(SystemConfigService $systemConfigService)
  19.     {
  20.         $this->systemConfigService = $systemConfigService;
  21.     }
  22.     
  23.     public function getSettingsAsArray(?string $salesChannelId = null): array
  24.     {
  25.         $values = $this->systemConfigService->getDomain(
  26.             self::SYSTEM_CONFIG_DOMAIN,
  27.             $salesChannelId,
  28.             true
  29.         );
  30.         $indexedValues = [];
  31.         
  32.         foreach ($values as $key => $value) 
  33.         {
  34.             $property = substr($key, strlen(self::SYSTEM_CONFIG_DOMAIN));
  35.             $indexedValues[$property] = $value;
  36.         }
  37.         return $indexedValues;
  38.     }
  39.     
  40.     public function getSettingsAsStruct(?string $salesChannelId = null): StructCollection
  41.     {
  42.         $settings = $this->getSettingsAsArray($salesChannelId);
  43.         
  44.         return (new StructCollection())->assign(
  45.             $settings
  46.         );
  47.     }
  48.     
  49. }