duan00529 2013-07-23 07:39 采纳率: 100%
浏览 35
已采纳

带有商店条件的ifconfig参数

In Magento xml layut or config file we can write ifconfig as parameter in a tag to apply a condition like this

<action method="addLink" translate="label title" module="contacts"     ifconfig="contacts/contacts/enabled">
<label>Contact Us</label>
<url>contacts</url>
<title>Contact Us</title>
<prepare>true</prepare>
</action>

I was trying to find ifconfig alternative of this function

Mage::getStoreConfig($path,Mage::app()->getStore());

so that i can include store condition along with path in ifconfig. Any help will be appreciated.

  • 写回答

2条回答 默认 最新

  • dongqu4443 2013-07-23 08:03
    关注

    There is no built in way to do that, mainly because the ifconfig constraint is used for the current store. When calling Mage::getStroreConfig() with only one parameter the current store is used as the second parameter. and the layout is loaded for the current store.
    But if you insist, here is a possible idea on how to do it.
    The action tags in the layout are parsed and applied in this method Mage_Core_Model_Layout::_generateAction(). This piece of code checks the ifconfig attribute.

    if (isset($node['ifconfig']) && ($configPath = (string)$node['ifconfig'])) {
        if (!Mage::getStoreConfigFlag($configPath)) {
            return $this;
        }
    }
    

    You can override this method to allow an additional parameter for the store. So your xml code would look like this:

    <action method="someMethod" ifconfig="some/config/path" store="2" />
    

    Now change the code above that calls the action to this:

    if (isset($node['ifconfig']) && ($configPath = (string)$node['ifconfig'])) {
        if (isset($node['store'])){//check config setting for supplied store
            if (!Mage::getStoreConfigFlag($configPath, $node['store'])) {
                return $this;
            }
        }
        else{//default behavior
            if (!Mage::getStoreConfigFlag($configPath)) {
                return $this;
            }
        }   
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教