How To Create Custom Source Model For Magento 2 System Configuration

How to create custom source modle for magento 2 system configuration

Have a look the following example code

system.xml

.....

            <field id="type" translate="label" type="select" sortOrder="110" showInDefault="1" showInWebsite="1" showInStore="0">
                <label>Payment Type</label>
                <source_model>\Vendor\Module\Model\Config\Source\Type</source_model>
            </field>

.....

module source file

\Vendor\Module\Model\Config\Source\Type.php

namespace Vendor\Module\Model\Config\Source;

class Type implements \Magento\Framework\Option\ArrayInterface{

    public function toOptionArray(){

        $options = array();
        $options[] = ['value'=>'sale','label'=>'Sale'];
        $options[] = ['value'=>'authorize','label'=>'Authorize'];

        return $options;
    }

}
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments