I have created a custom module and want to get specific customer group users to list in the dropdown.
For this I have gone through the admin > Stores > Other Settings > Customer Groups and I have created a customer group named ex. XYZ Customer. Assigned some users to XYZ Customer group.
Now, I want to list all the user who belongs to the XYZ customer group. How I can list all the users in the custom dropdown.
See below is my custom block code:
<?php
namespace Vendor\Mymodule\Block\Adminhtml\Order\View;
class Custom extends \Magento\Backend\Block\Template
{
protected $customerCollectionFactory;
public function __construct(
\Magento\Backend\Block\Template\Context $context,
\Magento\Customer\Model\ResourceModel\Customer\CollectionFactory $customerCollectionFactory,
array $data = []
){ $this->customerCollectionFactory = $customerCollectionFactory;
parent::__construct($context, $data);
}
public function getCustomerCollection()
{
$collection = $this->customerCollectionFactory->create();
$collection->addFieldToFilter("group_id","4");
$options = [];
//echo '<pre>'; print_r($collection); die;
foreach ($collection as $driver) {
$options[] = ['label' => $driver->getFirstname()." ".$driver->getLastname(), 'value' => $driver->getEntityId()];
}
//echo '<pre>'; print_r($options); die;
return $options;
}
}
Guys help me out this issue. Thanks
Best Answer
Create Block file in module Customer.php
Path :
App\Code\{CompanyName}\{ModuleName}\Block\Bookseller\
Create phtml file in module Customer.phtml
Path :
App\Code\{CompanyName}\{ModuleName}\Block\Bookseller\