1

Hi i have created a custom module and added a custom file upload link

Here is the output image

enter image description here

System.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
    <system>
        <tab id="test" translate="label" sortOrder="200">
            <label>
                Test
            </label>
        </tab>
        <section id="zipcode" translate="label" type="text" sortOrder="120" showInDefault="1" showInWebsite="1" showInStore="1">
            <label>Zipcode</label>
            <tab>test</tab>
            <resource>Learn_Module::config_module</resource>
            <group id="config" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="0" showInStore="0">
                <label>Check delivery postcode</label>
                <field id="enable" translate="label" type="select" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>Enabled</label>
                    <source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
                </field>
                <field id="postcodes" translate="label" type="textarea" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>Postcodes</label>
                    <comment>Comma-separated</comment>
                    <depends><field id="enable">1</field></depends>
                </field>


                <!-- csv file upload starts here -->
                <field id="custom_file_upload" translate="label" type="Magento\Config\Block\System\Config\Form\Field\File" sortOrder="30" showInDefault="1" showInWebsite="1" >
                 <label>Upload Csv File</label>
                 <backend_model>Magento\Config\Model\Config\Backend\File</backend_model>
                 <upload_dir>pub/media/myupload</upload_dir>
                </field>
                <!-- file upload ends here -->

                <field id="success_message" translate="label" type="text" sortOrder="21" showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>Success message</label>
                    <depends><field id="enable">1</field></depends>
                </field>
                <field id="error_message" translate="label" type="text" sortOrder="22" showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>Error message</label>
                    <depends><field id="enable">1</field></depends>
                </field>
            </group>
        </section>

    </system>
</config>

Now i want to upload csv file of zipcodes but am not totaly sure how to upload it can anyone please help me

1
  • if my answer was helpful, please accept my answer by clicking on the right sign below score of my answer. Feb 4, 2020 at 12:02

1 Answer 1

2

It would be the easiest if you add a custom backend model (for example Vendor\Module\Model\Config\Backend\Zipcode) to the config field in the system.xml file. Then use the afterSave() to save whatever you want.

Note: Your backend model class should extend \Magento\Framework\App\Config\Value class.

You can have a look at the following files for reference:

  • /vendor/magento/module-offline-shipping/Model/Config/Backend/Tablerate.php
  • /vendor/magento/module-offline-shipping/etc/adminhtml/system.xml

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.