We sacrifice by not doing any other technology, so that you get the best of Magento.

We sacrifice by not doing any other technology, so that you get the best of Magento.

    For any custom module we can add category drop down selection in system configuration.

    Let’s start with creating a module names Magemonkeys_Categorydropdown

    in adminhtml we can create file system.xml

    Here is code for call category selection

    <group id="categoryselection_setting" translate="label" type="text" default="1" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">
        <label>Setting</label>
        <field id="categorylist" translate="label" type="multiselect" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">
            <label>Please Select Category</label>
            <source_model>MagemonkeysCategorydropdownModelConfigSourceCategorylist</source_model>
        </field>
    </group>

    and then we can create file Categorylist.php in MagemonkeysCategorydropdownModelConfigSource

    <?php
    namespace MagemonkeysCategorydropdownModelConfigSource;
    
    use MagentoFrameworkOptionArrayInterface;
    
    class Categorylist implements ArrayInterface
    {
        protected $_categoryHelper;
    
        public function __construct(MagentoCatalogHelperCategory $catalogCategory)
        {
            $this->_categoryHelper = $catalogCategory;
        }
    
        public function getStoreCategories($sorted = false, $asCollection = false, $toLoad = true)
        {
            return $this->_categoryHelper->getStoreCategories($sorted , $asCollection, $toLoad);
        }
    
        public function toOptionArray()
        {
    
            $arr = $this->toArray();
            $ret = [];
    
            foreach ($arr as $key => $value)
            {
    
                $ret[] = [
                    'value' => $key,
                    'label' => $value
                ];
            }
    
            return $ret;
        }
    
        public function toArray()
        {
    
            $categories = $this->getStoreCategories(true,false,true);
    
            $catagoryList = array();
            foreach ($categories as $category){
    
                $catagoryList[$category->getEntityId()] = __($category->getName());
            }
    
            return $catagoryList;
        }
    
    }

    That’s it.

    field_5bfb909c5ccae

      Get a Free Quote