CustomerGroupConfig.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Customer\Model;
  7. /**
  8. * System configuration operations for customer groups.
  9. */
  10. class CustomerGroupConfig implements \Magento\Customer\Api\CustomerGroupConfigInterface
  11. {
  12. /**
  13. * @var \Magento\Config\Model\Config
  14. */
  15. private $config;
  16. /**
  17. * @var \Magento\Customer\Api\GroupRepositoryInterface
  18. */
  19. private $groupRepository;
  20. /**
  21. * @param \Magento\Config\Model\Config $config
  22. * @param \Magento\Customer\Api\GroupRepositoryInterface $groupRepository
  23. */
  24. public function __construct(
  25. \Magento\Config\Model\Config $config,
  26. \Magento\Customer\Api\GroupRepositoryInterface $groupRepository
  27. ) {
  28. $this->config = $config;
  29. $this->groupRepository = $groupRepository;
  30. }
  31. /**
  32. * @inheritdoc
  33. */
  34. public function setDefaultCustomerGroup($id)
  35. {
  36. if ($this->groupRepository->getById($id)) {
  37. $this->config->setDataByPath(
  38. \Magento\Customer\Model\GroupManagement::XML_PATH_DEFAULT_ID,
  39. $id
  40. );
  41. $this->config->save();
  42. }
  43. return $id;
  44. }
  45. }