moduleManager = $moduleManager; $this->groupRepository = $groupRepository; $this->searchCriteriaBuilder = $searchCriteriaBuilder; } /** * Return array of customer groups * * @return array */ public function toOptionArray() { if (!$this->moduleManager->isEnabled('Magento_Customer')) { return []; } $customerGroups = []; $customerGroups[] = [ 'label' => __('ALL GROUPS'), 'value' => (string)GroupInterface::CUST_GROUP_ALL, ]; /** @var GroupSearchResultsInterface $groups */ $groups = $this->groupRepository->getList($this->searchCriteriaBuilder->create()); foreach ($groups->getItems() as $group) { $customerGroups[] = [ 'label' => $group->getCode(), 'value' => $group->getId(), ]; } return $customerGroups; } }