【发布时间】:2018-05-04 04:31:21
【问题描述】:
我想如何在我的客户模块中显示客户组,例如“未登录 - 一般”或“未登录 - 一般 - 批发 - 零售商”,
这是我在网格中的代码
$this->addColumn(
'customer_group',
[
'header' => __('Customer Groups'),
'index' => 'customer_group',
'class' => 'customer_group',
'type' => 'options',
'renderer' => 'Rendy\ModuleWarehouse\Block\Adminhtml\Warehouse\Renderer\CustomerGroups'
]
);
这是我的代码 CustomerGroups
命名空间 Rendy\ModuleWarehouse\Block\Adminhtml\Warehouse\Renderer; 使用 Magento\Framework\DataObject; 类 CustomerGroups 扩展 \Magento\Backend\Block\Widget\Grid\Column\Renderer\AbstractRenderer { 受保护的 $_customerGroup;
public function __construct(
\Magento\Backend\Block\Context $context,
\Magento\Customer\Model\ResourceModel\Group\Collection $customerGroup,
array $data = []
) {
$this->_customerGroup = $customerGroup;
parent::__construct($context, $data);
}
/**
* Get customer groups
*
* @return array
*/
public function render(DataObject $row) {
$customerGroups = $this->_customerGroup->toOptionArray();
array_unshift($customerGroups, array('value'=>'', 'label'=>'Any'));
}
}
谢谢
【问题讨论】: