2014-10-10 74 views
1

在管理面板菜單 - >配置我有一個選項卡。 我使用:Magento system.xml組multiselect

<frontend_type>Multiselect</frontend_type> 
<source_model>adminhtml/system_config_source_customer_group_multiselect</source_model> 

,我得到了三個用戶,即一般,零售,WHOLESELER。

問題,如何獲得第四組,即一個NOT LOGGED IN?

+0

NOT LOGGED IN的處理方式有點不同,例如,您無法在該組中創建客戶,因此此源模型未返回該客戶。 – user3154108 2014-10-10 09:31:37

+0

我不需要在這個組中創建客戶,我需要多次選擇與其他組不相關的組 – 2014-10-10 09:34:38

+0

問題是,您使用的源模型用於客戶創建選項卡,其中NOT LOGGED IN組是不需要,所以這個源模型不包括該組。我不知道有其他源模型,您必須創建自己的模型或手動添加該組。 – user3154108 2014-10-10 09:38:20

回答

3

而不是調用內核模式的,你可以在的system.xml

定義自己的觀察員請從下面的代碼,這將解決您的問題。

<source_model>adminhtml/system_config_source_GroupCollection</source_model> 

現在在您的本地\ community(工作目錄)下面的路徑中創建您的GroupCollection.php文件。

e.g app\code\local\Mage\Adminhtml\Model\System\Config\Source\GroupCollection.php 

在該文件中添加以下代碼。

<?php 
class Mage_Adminhtml_Model_System_Config_Source_GroupCollection 
{ 
/** 
    * Options getter 
    * 
    * @return array 
    */ 
    public function toOptionArray() 
    { 
     $group = Mage::getModel('customer/group')->getCollection(); 
     $groupArray = array(); 
     foreach ($group as $eachGroup) { 
     $groupData = array(
        'customer_group_id' => $eachGroup->getCustomerGroupId(), 
        'customer_group_code' => $eachGroup->getCustomerGroupCode(), 
        'tax_class_id' => $eachGroup->getTaxClassId() // we dont required this 
        ); 
     if (!empty($groupData)) { 
      array_push($groupArray, $groupData); 
     } 
     } 
      var_dump($groupArray); 
    } 
} 

以下將是您的輸出。

array (size=4) 
    0 => 
    array (size=3) 
     'customer_group_id' => string '0' (length=1) 
     'customer_group_code' => string 'NOT LOGGED IN' (length=13) 
     'tax_class_id' => string '3' (length=1) 
    1 => 
    array (size=3) 
     'customer_group_id' => string '1' (length=1) 
     'customer_group_code' => string 'General' (length=7) 
     'tax_class_id' => string '3' (length=1) 
    2 => 
    array (size=3) 
     'customer_group_id' => string '2' (length=1) 
     'customer_group_code' => string 'Wholesale' (length=9) 
     'tax_class_id' => string '3' (length=1) 
    3 => 
    array (size=3) 
     'customer_group_id' => string '3' (length=1) 
     'customer_group_code' => string 'Retailer' (length=8) 
     'tax_class_id' => string '3' (length=1) 

而你完成了! :)

+1

謝謝,我嘗試做你說的和它的工作,但那並不完全是我所需要的,我重寫了這樣的核心模塊, public function toOptionArray() if(!$ this - > _ options){ $ this - > _ options = Mage :: getResourceModel('customer/group_collection') - > loadData() - > toOptionArray(); } return $ this - > _ options; } 只是刪除了這一點: - > setRealGroupsFilter() 從代碼 – 2014-10-10 10:31:06

+0

沒有你,我也不會想到這一點! – 2014-10-10 10:32:48

1

你不需要在'本地'創建'法師'目錄或重寫核心模塊!如果你將看到app/code/core/Mage/Adminhtml/Model/System/Config/Source/Customer/Group/Multiselect.php,你會看到這個類不會延伸任何東西!所以,你可以在你的文件夾NameSpace/ModuleName/Model自己創造Exemple.php,只是複製所有從Multiselect.php到Exemple.php,修復有你想要什麼(你的情況只是刪除->setRealGroupsFilter()字符串),並在system.xml中設置你的模型。 對於爲例,如果在你的config.xml你有

<models> 
    <my_model> 
     <class>NameSpace_ModuleName_Model</class> 
    </my_model> 
</models> 

比你寫

<source_model>my_model/exemple</source_model> 
在你的system.xml