2013-07-23 25 views
0

在Magento XML layut或配置文件中,我們可以寫的ifconfig作爲參數標籤應用的條件這樣使用ifconfig參數

<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> 

我試圖找到這個函數的使用ifconfig替代

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

這樣我可以在ifconfig中包含存儲條件和路徑。 任何幫助將不勝感激。

回答

2

有沒有建立這樣做,主要是因爲ifconfig約束是用於當前的商店。當僅用一個參數調用Mage::getStroreConfig()時,當前商店被用作第二參數。併爲當前商店加載佈局。
但是,如果你堅持,這是一個關於如何做到這一點的可能想法。
該佈局中的action標籤被解析並應用於此方法Mage_Core_Model_Layout::_generateAction()。這段代碼檢查ifconfig屬性。

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

您可以重寫此方法以允許存儲的其他參數。所以,你的XML代碼應該是這樣的:

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

現在改變上面的代碼調用的動作是:

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; 
     } 
    } 
} 
+0

感謝馬維斯。幾乎沒有改變你的解決方案滿足了我的要求。我設置了store =「true」而不是store =「2」,並寫入store =「true」,而不是if(!Mage :: getStoreConfigFlag($ configPath,$ node ['store'])) :: getStoreConfigFlag($ configPath,Mage :: app() - > getStore()))這樣就需要當前的商店設置。 –

+0

首先是馬呂斯(不是馬維斯):)。其次,如果您想檢查當前商店的配置值,則不需要第二個參數。如果未提供第二個參數,則檢查當前商店的值。 – Marius

0

嘗試Conditive擴展使用ifconfig extension