📜  magento 2 为模块生成白名单 (1)

📅  最后修改于: 2023-12-03 15:17:29.576000             🧑  作者: Mango

Magento 2 White List Generation for Modules

Introduction

Magento 2 is a popular open-source e-commerce platform that allows users to create online stores with various functionalities. In order for a module to be able to function properly within the Magento 2 ecosystem, it needs to be added to the white list.

The white list is a list of safe and trusted modules that can be loaded by Magento 2. By default, all modules are not white-listed, so adding a module to the white list is necessary to enable its functionality within your store.

This guide will explain how to generate a white list for Magento 2 modules, and also how to add a module to the white list so it can be loaded by the platform.

Generating a White List

To generate a white list for Magento 2 modules, you'll need to use the Magento CLI. First, navigate to the root directory of your Magento installation.

cd /path/to/magento

Once you are in the root directory, run the following command:

bin/magento module:status --all | grep -v List | grep -v None | awk '{printf $1" "}' > var/whitelist.txt

This command will generate a file called var/whitelist.txt in your Magento 2 installation's directory. This file contains the names of all the installed modules in your Magento 2 store.

Adding a Module to the White List

To add a module to the white list, you'll need to modify the app/code/<Vendor>/<Module>/etc/module.xml file. In this file, you will add the following code snippet:

<config>
    <default>
        <modules>
            <Vendor_Module>
                <active>true</active>
                <codePool>local</codePool>
            </Vendor_Module>
        </modules>
    </default>
    <whitelist>
        <allowed_modules>
            <Vendor_Module/>
        </allowed_modules>
    </whitelist>
</config>

In this snippet, replace <Vendor> and <Module> with the actual name of your module. Once you have added this snippet to the module.xml file, save the file and run the following command:

bin/magento setup:upgrade

This will apply the changes you have made to the module.xml file, and add your module to the white list.

Conclusion

By following the steps outlined in this guide, you should now be able to generate a white list for your Magento 2 modules and add new modules to the white list as well. This will enable your modules to function correctly within your Magento 2 store.