在管理面板菜单->配置,我有一个标签。我在用:
<frontend_type>Multiselect</frontend_type>
<source_model>adminhtml/system_config_source_customer_group_multiselect</source_model>我有三个用户组,一般,零售,WHOLESELER。
问,如何获得第四组,即一个未登录?
发布于 2014-10-10 09:43:17
您可以在system.xml中定义自己的观察者,而不是调用核心模型
请找到下面的代码,这将解决您的问题。
<source_model>adminhtml/system_config_source_GroupCollection</source_model>现在,在路径下面的本地\社区(工作目录)中创建您的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)你就完了!:)
发布于 2015-10-15 10:44:30
您不需要创建‘法师’目录在‘本地’或重写核心模块!如果您查看一下app/code/core/Mage/Adminhtml/Model/System/Config/Source/Customer/Group/Multiselect.php,,您会发现这个类没有扩展任何东西!因此,您可以在文件夹NameSpace/ModuleName/Model中创建自己的Exemple.php,只需将all从Multiselect.php复制到Exemple.php,fix --您想要什么(在您的示例中只是删除->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里!
https://stackoverflow.com/questions/26295631
复制相似问题