How to get all list of customer group?
I was able to get solution using the below code:
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$groupOptions = $objectManager->get('\Magento\Customer\Model\ResourceModel\Group\Collection')->toOptionArray();
$fieldset->addField(
'customer_group',
'multiselect',
[
'name' => 'customer_group[]',
'label' => __('Customer Group'),
'title' => __('Customer Group'),
'values' => $groupOptions,
'disabled' => $isElementDisabled
]
);
You can use the following class: Magento\Customer\Model\Customer\Source\Group
.
It provides a toOptionArray
method that you can use to get an array of customer groups