0
votes

how i want to show customer groups in my custome module, like "NOT LOGGED IN - General" or "NOT LOGGED IN - General - Wholesale - Retailer",

this is my code in grid

$this->addColumn(
        'customer_group',
        [
            'header' => __('Customer Groups'),
            'index' => 'customer_group',
            'class' => 'customer_group',
            'type' => 'options',
            'renderer' => 'Rendy\ModuleWarehouse\Block\Adminhtml\Warehouse\Renderer\CustomerGroups'
        ]
    );

and this is my code CustomerGroups

namespace Rendy\ModuleWarehouse\Block\Adminhtml\Warehouse\Renderer; use Magento\Framework\DataObject; class CustomerGroups extends \Magento\Backend\Block\Widget\Grid\Column\Renderer\AbstractRenderer { protected $_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'));
}

}

thank you

1

1 Answers

1
votes

Ever get this solved? You could use \Magento\Customer\Model\GroupFactory in your construct:

public function __construct(
    \Magento\Backend\Block\Context $context,
    \Magento\Customer\Model\GroupFactory $groupFactory        
    array $data = []
) {
    $this->_groupFactory = $groupFactory;        
    parent::__construct($context, $data);
}

It is nice because you can then do in your render function:

$collection = $this->groupFactory->create()->getCollection();
foreach ($collection as $group) {
  echo "group id ".$group->getId();
  echo "group code ".$group->getCode();
}