CustomerGroupsOptionsProvider.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\CatalogRule\Model\Rule;
  7. class CustomerGroupsOptionsProvider implements \Magento\Framework\Data\OptionSourceInterface
  8. {
  9. /**
  10. * @var \Magento\Customer\Api\GroupRepositoryInterface
  11. */
  12. private $groupRepository;
  13. /**
  14. * @var \Magento\Framework\Api\SearchCriteriaBuilder
  15. */
  16. private $searchCriteriaBuilder;
  17. /**
  18. * @var \Magento\Framework\Convert\DataObject
  19. */
  20. private $objectConverter;
  21. /**
  22. * @param \Magento\Customer\Api\GroupRepositoryInterface $groupRepository
  23. * @param \Magento\Framework\Api\SearchCriteriaBuilder $searchCriteriaBuilder
  24. * @param \Magento\Framework\Convert\DataObject $objectConverter
  25. */
  26. public function __construct(
  27. \Magento\Customer\Api\GroupRepositoryInterface $groupRepository,
  28. \Magento\Framework\Api\SearchCriteriaBuilder $searchCriteriaBuilder,
  29. \Magento\Framework\Convert\DataObject $objectConverter
  30. ) {
  31. $this->groupRepository = $groupRepository;
  32. $this->searchCriteriaBuilder = $searchCriteriaBuilder;
  33. $this->objectConverter = $objectConverter;
  34. }
  35. /**
  36. * @return array
  37. */
  38. public function toOptionArray()
  39. {
  40. $customerGroups = $this->groupRepository->getList($this->searchCriteriaBuilder->create())->getItems();
  41. return $this->objectConverter->toOptionArray($customerGroups, 'id', 'code');
  42. }
  43. }