我在Google Analytics模块中添加了一个字段。 (所以这个问题是一般的问题,在这种情况下是分析模块)
看起来像这样(system.xml)
<another_code translate="label">
<label>Another code</label>
<frontend_type>text</frontend_type>
<sort_order>10</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<fields>
<active translate="label">
<label>Enable</label>
<frontend_type>select</frontend_type>
<source_model>adminhtml/system_config_source_yesno</source_model>
<sort_order>10</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</active>
<account translate="label">
<label>Account Id</label>
<frontend_type>text</frontend_type>
<sort_order>20</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</account>
</fields>
</another_code>
这很好用,可以添加到数据库中。但...
如何在前端获取它?如果我想获得<label>Account Id</label>
答案 0 :(得分:2)
从上面的示例中获取“帐户ID”值
法师:: getStoreConfig( '谷歌/ another_code /帐户')
对核心进行更改绝不是一个好主意,因此您可以创建自定义模块来扩展Google Analytics
在app / code / local / MageIgniter / GoogleAnalytics / etc / system.xml中(从上面复制system.xml)
<config>
<sections>
<google translate="label" module="googleanalytics">
<label>Google API</label>
<tab>sales</tab>
....
<another_code translate="label">
在app / code / local / MageIgniter / GoogleAnalytics / etc / config.xml
<config>
<modules>
<MageIgniter_GoogleAnalytics>
<version>0.1.0</version>
</MageIgniter_GoogleAnalytics>
</modules>
<global>
<blocks>
<googleanalytics>
<rewrite>
<ga>MageIgniter_GoogleAnalytics_Block_Ga</ga>
</rewrite>
</googleanalytics>
</blocks>
</global>
</config>
在/app/code/local/MageIgniter/GoogleAnalytics/Block/Ga.php中创建
class MageIgniter_GoogleAnalytics_Block_Ga extends Mage_GoogleAnalytics_Block_Ga
{
function _getPageTrackingCode($accountId){
// to get 'Account Id' value from above example
Mage::getStoreConfig('google/another_code/account')
}
........
}
请参阅/app/code/core/Mage/GoogleAnalytics/Block/Ga.php或Custom variables on product details page in Magento以获取更多帮助
答案 1 :(得分:0)
我假设你的意思是在System > Configuration
屏幕上看不到你的新选项。您需要将another_code
节点添加到配置的ACL节点中(通常位于adminhtml.xml中)。不要忘记清除缓存并注销/重新加载acl权限。正如@ R.S所说,如果你正在编辑核心,你肯定应该考虑创建一个自定义模块。