Magento 2 – How to get multiselect option in system configuration using system.xml.

Using below demo we can get multiselect option using system.xml.
For Example, We will get all Customer group of a system and display all the customer group by system.xml in System -> Configuration Section of admin.
Create system.xml file,
Path,   app/code/<Vendorname>/<Modulename>/etc/adminhtml/system.xml

You need to get the collection of all customer group using a Model file. Create Model file in your module. You can define your model php file using source_model tag in system.xml file.

Create Group.php file,
Path, app/code/<Vendorname>/<Modulename>/Model/Adminhtml/System/Config/Source/Customer/Group.php

Clear Cache using php bin/magento cache:flush

Now You can get the list of customer group in your section with multi-select option.
If you want to get the list of all selected option in PHP file,

Using the above way you can list of all customer group selected in a Configuration section. The result will be a value of all selected customer group with comma separated.

Leave a Reply

Your email address will not be published. Required fields are marked *