Magento 如何使用模块配置文件中的 module_name 标签元素

问题描述 投票:0回答:1

我发现here Magento 使用这些标签作为自定义配置变量,但我仍然无法理解它们在哪里使用以及如何使用。 例如,Wishlist 模块在其定义的 config.xml 文件中具有 wishlist(与模块同名)xml 标签:

<item>
    <product_attributes>
        <visibility/>
        <url_path/>
        <url_key/>
    </product_attributes>
</item>

该模块在哪里使用这些配置? 另外,如果我要构建付款方式,我必须在自定义模块 config.xml 中添加 sales 的标签,然后添加 quote 的标签,依此类推... 我还发现了其他相关问题,但大多数答案是这些标签可以是任何东西,但我需要知道系统如何使用它们。 先谢谢你了

php magento config
1个回答
3
投票

在这种情况下,直接负责的文件是

app/code/core/Mage/Wishlist/Model/Config.php
,其中完全由以下内容组成:

class Mage_Wishlist_Model_Config
{
    const XML_PATH_PRODUCT_ATTRIBUTES = 'global/wishlist/item/product_attributes';

    /**
     * Get product attributes that need in wishlist
     *
     */
    public function getProductAttributes()
    {
        $attrsForCatalog  = Mage::getSingleton('catalog/config')->getProductAttributes();
        $attrsForWishlist = Mage::getConfig()->getNode(self::XML_PATH_PRODUCT_ATTRIBUTES)->asArray();

        return array_merge($attrsForCatalog, array_keys($attrsForWishlist));
    }
}

因此,每当您需要专门读取配置时,只需使用

Mage::getConfig()->getNode()
并传递您感兴趣的节点的路径。在本例中,路径是
global/wishlist/item/product_attributes
,您已经知道了。

每个模块都会根据需要读取其配置,并且没有正式的定义。这种灵活性允许任何模块为任何其他模块的设置做出贡献。

© www.soinside.com 2019 - 2024. All rights reserved.