而不是調用內核模式的,你可以在的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)
而你完成了! :)
NOT LOGGED IN的處理方式有點不同,例如,您無法在該組中創建客戶,因此此源模型未返回該客戶。 – user3154108 2014-10-10 09:31:37
我不需要在這個組中創建客戶,我需要多次選擇與其他組不相關的組 – 2014-10-10 09:34:38
問題是,您使用的源模型用於客戶創建選項卡,其中NOT LOGGED IN組是不需要,所以這個源模型不包括該組。我不知道有其他源模型,您必須創建自己的模型或手動添加該組。 – user3154108 2014-10-10 09:38:20