Magento: how do I add an additional multiselect in admin config settings for a shipping module?

Magento: how do I add an additional multiselect in admin config settings for a shipping module?

September 27, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento: how do I add an additional multiselect in admin config settings for a shipping module?

Extending Magento Admin Config Settings: Adding Multiple Multiselects

Adding custom multiselect options to the Magento admin panel’s configuration settings allows you to integrate advanced functionalities seamlessly into your shipping module. In this guide, we’ll explore how to create a second multiselect field within your own fieldset, even if it requires additional values stored in an external table.

Defining Your Custom Multiselect in system.xml

As demonstrated in the provided system.xml snippet, you can define a new multiselect configuration setting by following this format:

<custommultiselect translate="label">
    <label>Your Custom Label</label>
    <frontend_type>multiselect</frontend_type>
    <sort_order>100</sort_order>
    <source_model>your_module/config_source_your_table</source_model>
    <show_in_default>1</show_in_default>
    <show_in_website>1</show_in_website>
    <show_in_store>1</show_in_store>
</custommultiselect>

Notice the following key elements:

  • Replace your_module with your actual module name.
  • Replace config_source_your_table with a custom model that will pull values from your external table. We’ll discuss this in detail below.

Creating Your Custom Source Model

To populate the multiselect options, you need to create a custom source model that extends \Magento\Eav\Model\Entity\Attribute\Source\AbstractSource. This model should fetch data from your external database table and prepare it for the multiselect frontend.

Create a new file at app/code/YourCompany/YourModule/etc/source/ConfigSourceCustomTable.php:

namespace YourCompany\YourModule\etc\source;

use Magento\Eav\Model\Entity\Attribute\Source\AbstractSource;
use Magento\Framework\App\ResourceConnection;

class ConfigSourceCustomTable extends AbstractSource
{
    protected $connection;

    public function __construct(ResourceConnection $resource)
    {
        $this->connection = $resource->getConnection();
    }

    public function getAllOptions()
    {
        $options = $this->connection->fetchAll('SELECT option_id, title FROM your_table');

        return [
            '' => '',
            ...array_combine(array_column($options, 'option_id'), array_column($options, 'title')),
        ];
    }
}

Ensure to replace your_table with the actual name of your external table.

Registering Your Custom Source Model

To make Magento recognize your custom source model, add it to your module’s configuration:

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="YourCompany_YourModule" setup_version="1.0.0">
        <sequence>
            <module name="Magento_Config"/>
        </sequence>
    </module>
</config>

Linking Your Custom Fieldset

To display your new multiselect within a specific fieldset, update the fieldsets section of your system.xml file accordingly:

<fieldset id="section_fieldset">
    <legend><translate>Your Fieldset Legend</translate></legend>
    <comment><translate>Your Fieldset Comment</translate></comment>
    <field name="your_module_field" translate="label" sort_order="20" show_in_default="1" show_in_website="1" show_in_store="0">
        <label><translate>Your Field Label</translate></label>
        <frontend_type>multiselect</frontend_type>
        <source_model>YourCompany\YourModule\etc\source\ConfigSourceCustomTable</source_model>
    </field>
</fieldset>

Conclusion

By following this comprehensive guide, you can successfully add a second multiselect to your Magento admin panel’s configuration settings. This extension enables you to enhance the functionality of your shipping module by leveraging additional data from external tables.

Remember, the key steps involve defining your custom field in system.xml, creating the corresponding source model, and linking it within an appropriate fieldset.

If you’re looking for more advanced Magento development techniques or need expert assistance with custom integrations, consider reaching out to our professional team at Laravel Company. We specialize in delivering high-quality solutions tailored to your specific business needs.

Database Extensions Themes Admin

Our network