Pregunta

I have created admin form. I am able to get customer group list using below code, but there is no "NOT LOGIN" group name so how can I get all group list?

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$groupOptions = $objectManager->get('\Magento\Customer\Model\Customer\Attribute\Source\Group')->getAllOptions();

$fieldset->addField(
    'customer_group',
    'multiselect',
    [
        'name' => 'customer_group[]',
        'label' => __('Customer Group'),
        'title' => __('Customer Group'),
        'values' => $groupOptions,
        'disabled' => $isElementDisabled
    ]
);

I am getting this output:

enter image description here

¿Fue útil?

Solución

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
    ]
);

Otros consejos

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

Licenciado bajo: CC-BY-SA con atribución
No afiliado a magento.stackexchange
scroll top