How to use config.php file effective in magento 2

Written by Jigar Patel

Jan 08, 2023

How to use config.php file effective in magento 2

The app/etc/config.php file is used to manage to enable/disable the modules in Magento 2 but it is used for other purposes as well which will reduce our manual work for many developers.

The config.php file contains the following sections:

  • i18n All inline translation data. Reading from this section is not supported.
  • modules The list of enabled and disabled modules.
  • scopes The list of stores, store groups, and websites with related information.
  • system The system configurations required for static content deployment.
  • themes The configuration of installed themes.

Modules

Manage the status(enable/disable) of the modules.

When we want to disable all the unnecessary/unused modules from the Magento 2 then instead of disabling the modules from each developer system, we can disable the modules from the config.php file .

The value 1 sets a module as enabled and 0 sets as disabled.

Suppose we wanted to disable modules from the Magento installation, the below snippet should do the job.

'modules' => [
    'Magento_Theme' => 0,
    'Magento_Backend' => 0,
]

Suppose we wanted to enable modules from the Magento installation, the below snippet should do the job.

'modules' => [ 
    'Magento_Store' => 1,
    'Magento_Eav' => 1 
]

Scopes

Create websites, store groups, and store views with the required information.

We are working with a project which contains multiple websites/store groups/store views and when we have more developers in the team then instead of creating the websites/store groups/store views from the admin panel in each developer system, we can add the code in the config.php file. This file can be pushed to the version control tool from there the developers can pull the code and run the setup:upgrade or app:config:import command which will create the websites/store groups/store views.

'scopes' => [
        'websites' => [
            'admin' => [
                'website_id' => '0',
                'code' => 'admin',
                'name' => 'Admin',
                'sort_order' => '0',
                'default_group_id' => '0',
                'is_default' => '0'
            ],
            'base' => [
                'website_id' => '1',
                'code' => 'base',
                'name' => 'Singapore Website',
                'sort_order' => '0',
                'default_group_id' => '1',
                'is_default' => '1'
            ],
            'india' => [
                'website_id' => '3',
                'code' => 'india_website',
                'name' => 'India Website',
                'sort_order' => '20',
                'default_group_id' => '3',
                'is_default' => '0'
            ]
        ],
        'groups' => [
            [
                'group_id' => '0',
                'website_id' => '0',
                'name' => 'Default',
                'root_category_id' => '0',
                'default_store_id' => '0',
                'code' => 'default'
            ],
            [
                'group_id' => '1',
                'website_id' => '1',
                'name' => 'Dubai Website Group',
                'root_category_id' => '2',
                'default_store_id' => '1',
                'code' => 'main_website_store'
            ],
            [
                'group_id' => '3',
                'website_id' => '3',
                'name' => 'Mumbai Website Group',
                'root_category_id' => '2',
                'default_store_id' => '3',
                'code' => 'mumbai_website_group'
            ]
        ],
        'stores' => [
            'admin' => [
                'store_id' => '0',
                'code' => 'admin',
                'website_id' => '0',
                'group_id' => '0',
                'name' => 'Admin',
                'sort_order' => '0',
                'is_active' => '1'
            ],
            'default' => [
                'store_id' => '1',
                'code' => 'default',
                'website_id' => '1',
                'group_id' => '1',
                'name' => 'Singapore Store View',
                'sort_order' => '0',
                'is_active' => '1'
            ],
            'mumbai_store' => [
                'store_id' => '3',
                'code' => 'mumbai_eng_store',
                'website_id' => '3',
                'group_id' => '3',
                'name' => 'Mumbai English Store View',
                'sort_order' => '20',
                'is_active' => '1'
            ],
            'mumbai_store_andh' => [
                'store_id' => '4',
                'code' => 'mumbai_andh_store',
                'website_id' => '3',
                'group_id' => '3',
                'name' => 'Mumbai Andh Store View',
                'sort_order' => '30',
                'is_active' => '1'
            ]
        ]
    ],

System

Manage the system configuration values.

We can maintain the same system configuration values across all the developers within a team so the developers no need to make the changes manually.

We can define the values in all the scopes(Global, Website, Store view), we will need to add the values inside the particular scope with the config path.

Once the values are defined in the config.php file they can’t be changed from the admin panel. The values which are defined on the config.php file will take the top priority.

'system'=> [ 
  'default' =>[ 
    'checkout' => [ 
      'cart' => [ 
        'delete_quote_after' => 31 
      ] 
    ] 
  ] 
]

themes

Contains an array of values for theme configuration.

'themes' => [
  'frontend/Magento/luma' => [
    'parent_id' => 'Magento/blank',
    'theme_path' => 'Magento/luma',
    'theme_title' => 'Magento Luma',
    'is_featured' => '0',
    'area' => 'frontend',
    'type' => '0',
    'code' => 'Magento/luma'
  ]
]

 

I Hope, This instruction will be helpful for you.

Happy Coding with magento2!! 🙂

If you have any difficulties regarding this blog, do consider them posting in the Comments section below!

I’m here to help.

Thank you!

Jigar Patel

Author

We can help you with

  • Dedicated Team
  • Setup Extended Team
  • Product Development
  • Custom App Development

Schedule a Developer Interview And Get 7 Days Risk-Free Trial

Fill out This Form and one of Our Technical Experts will Contact you Within 12 Hours.

    Google
    |

    4.8

    Google
    |

    4.8

    Google
    |

    4.9

    Google
    |

    4.8

    Google
    |

    4.9

    Copyright © 2024 DOLPHIN WEB SOLUTION. All rights reserved.

    TO TOP