0

I need to display all customer groups in dropdown in magento2 admin configuration but customer group_renderer is not working. can anyone please help me.

public function _prepareToRender()
    {  
        /** @var CustomAdminConfigHelperData $helper */
        $helper = $this->helperData;


        $this->addColumn('referral_url', ['label' => __('Referral URL / Domain'),'style' => 'width:200px']);
        $this->addColumn('customer_group', ['label' => __('Customer Group'),'style' => 'width:200px','renderer' => $this->_getGroupRenderer()]);

        $this->_addAfter = false;
        $this->_addButtonLabel = __('Add');
    }
    protected function  _getGroupRenderer() 
    {
        if (!$this->_itemRenderer) { 
            $this->_itemRenderer = $this->viewLayoutFactory->create()->createBlock(
                'Customergroupauto/GroupConfig/Groups', '',
                ['is_render_to_js_template' => true]
            );
        }
        return $this->_itemRenderer;
    }

1 Answer 1

0

Try this

 /**
 * Customer Group
 *
 * @var \Magento\Customer\Model\ResourceModel\Group\Collection
 */
protected $_customerGroup;

/**
 * @param \Magento\Backend\Block\Template\Context $context
 * @param \Magento\Customer\Model\ResourceModel\Group\Collection $customerGroup
 * @param array $data
 */
public function __construct(
    \Magento\Backend\Block\Template\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 getCustomerGroups() {
    $customerGroups = $this->_customerGroup->toOptionArray();
    array_unshift($customerGroups, array('value'=>'', 'label'=>'Any'));
    return $customerGroups;
}
5
  • thanks for update but i need to customer group down in Column. Apr 3, 2019 at 11:44
  • like dropdown???
    – Asad Khan
    Apr 3, 2019 at 11:46
  • yes, i like all group names come under dropown Apr 3, 2019 at 11:59
  • then you just need to add <field id="link" translate="label" type="select" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1"> type="select" in the configuration (system.xml)
    – Asad Khan
    Apr 3, 2019 at 12:02
  • I need to pass the data like this 'renderer' => $this->_getGroupRenderer() Apr 3, 2019 at 13:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.