Magento 2 get specific customer group customers list
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 VendorMymoduleBlockAdminhtmlOrderView;
class Custom extends MagentoBackendBlockTemplate
{
protected $customerCollectionFactory;
public function __construct(
MagentoBackendBlockTemplateContext $context,
MagentoCustomerModelResourceModelCustomerCollectionFactory $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
magento2 customer customer-group magento2.1.5
add a comment |
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 VendorMymoduleBlockAdminhtmlOrderView;
class Custom extends MagentoBackendBlockTemplate
{
protected $customerCollectionFactory;
public function __construct(
MagentoBackendBlockTemplateContext $context,
MagentoCustomerModelResourceModelCustomerCollectionFactory $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
magento2 customer customer-group magento2.1.5
add a comment |
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 VendorMymoduleBlockAdminhtmlOrderView;
class Custom extends MagentoBackendBlockTemplate
{
protected $customerCollectionFactory;
public function __construct(
MagentoBackendBlockTemplateContext $context,
MagentoCustomerModelResourceModelCustomerCollectionFactory $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
magento2 customer customer-group magento2.1.5
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 VendorMymoduleBlockAdminhtmlOrderView;
class Custom extends MagentoBackendBlockTemplate
{
protected $customerCollectionFactory;
public function __construct(
MagentoBackendBlockTemplateContext $context,
MagentoCustomerModelResourceModelCustomerCollectionFactory $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
magento2 customer customer-group magento2.1.5
magento2 customer customer-group magento2.1.5
edited Jan 17 at 5:32
Utsav Gupta
17613
17613
asked May 30 '17 at 10:08
mageDev0688mageDev0688
345725
345725
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
You can use filter in customer collection as follows
->addFieldToFilter('customer_group_id','1');
where 1 is customer group id.
But how I can get customer collection first? Could you please let me know complete process. I have created a block in my custom module to display the dropdown list.
– mageDev0688
May 30 '17 at 10:23
Please paste your code in question by editing it
– Kishan Patadia
May 30 '17 at 10:23
You can see the complete module code in this Question.
– mageDev0688
May 30 '17 at 10:26
After this I want to save these customer ID in custom table as well in respect of order id.
– mageDev0688
May 30 '17 at 10:29
please check the updated question. I have tried with your code->addFieldToFilter('customer_group_id','1');
, but when I use thecustomer_group_id
the function will stuck.
– mageDev0688
May 30 '17 at 12:26
add a comment |
protected $_customerCollectionFactory;
public function __construct(
MagentoFrameworkViewElementTemplateContext $context,
MagentoCustomerModelResourceModelCustomerCollectionFactory $customerCollectionFactory,
array $data =
)
{
$this->_context = $context;
$this->_customerCollectionFactory = $customerCollectionFactory;
parent::__construct($context, $data);
}
public function getCustomerCollection() {
$collection = $this->_customerCollectionFactory->create();
$collection->addFieldToFilter("group_id","3");
return $collection->getData();
}
add a comment |
You can get customer group details and specific group member's customer ids by doing like this
class Trial extends MagentoFrameworkViewElementTemplate
{
protected $_customerGroup;
protected $_customerFactory;
public function __construct(
MagentoBackendBlockTemplateContext $context,
MagentoCustomerModelGroup $customerGroupCollection,
MagentoCustomerModelCustomerFactory $customerFactory,
array $data =
) {
$this->_customerGroupCollection = $customerGroupCollection;
$this->_customerFactory=$customerFactory;
parent::__construct($context, $data);
}
public function getCustomerGroup($currentGroupId)
{
//Get customer group Id , you have already this so directly get name
$collection = $this->_customerGroupCollection-
>load($currentGroupId);
echo $collection->getCustomerGroupCode();//Get group name
print_r($collection->getData());
}
public function getCustomer($customergroupId)
{
return $this->_customerFactory->create()->getCollection()-
>addFieldToFilter('group_id', $customergroupId);
}
}
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "479"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f176607%2fmagento-2-get-specific-customer-group-customers-list%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can use filter in customer collection as follows
->addFieldToFilter('customer_group_id','1');
where 1 is customer group id.
But how I can get customer collection first? Could you please let me know complete process. I have created a block in my custom module to display the dropdown list.
– mageDev0688
May 30 '17 at 10:23
Please paste your code in question by editing it
– Kishan Patadia
May 30 '17 at 10:23
You can see the complete module code in this Question.
– mageDev0688
May 30 '17 at 10:26
After this I want to save these customer ID in custom table as well in respect of order id.
– mageDev0688
May 30 '17 at 10:29
please check the updated question. I have tried with your code->addFieldToFilter('customer_group_id','1');
, but when I use thecustomer_group_id
the function will stuck.
– mageDev0688
May 30 '17 at 12:26
add a comment |
You can use filter in customer collection as follows
->addFieldToFilter('customer_group_id','1');
where 1 is customer group id.
But how I can get customer collection first? Could you please let me know complete process. I have created a block in my custom module to display the dropdown list.
– mageDev0688
May 30 '17 at 10:23
Please paste your code in question by editing it
– Kishan Patadia
May 30 '17 at 10:23
You can see the complete module code in this Question.
– mageDev0688
May 30 '17 at 10:26
After this I want to save these customer ID in custom table as well in respect of order id.
– mageDev0688
May 30 '17 at 10:29
please check the updated question. I have tried with your code->addFieldToFilter('customer_group_id','1');
, but when I use thecustomer_group_id
the function will stuck.
– mageDev0688
May 30 '17 at 12:26
add a comment |
You can use filter in customer collection as follows
->addFieldToFilter('customer_group_id','1');
where 1 is customer group id.
You can use filter in customer collection as follows
->addFieldToFilter('customer_group_id','1');
where 1 is customer group id.
answered May 30 '17 at 10:20
Kishan PatadiaKishan Patadia
3,5501923
3,5501923
But how I can get customer collection first? Could you please let me know complete process. I have created a block in my custom module to display the dropdown list.
– mageDev0688
May 30 '17 at 10:23
Please paste your code in question by editing it
– Kishan Patadia
May 30 '17 at 10:23
You can see the complete module code in this Question.
– mageDev0688
May 30 '17 at 10:26
After this I want to save these customer ID in custom table as well in respect of order id.
– mageDev0688
May 30 '17 at 10:29
please check the updated question. I have tried with your code->addFieldToFilter('customer_group_id','1');
, but when I use thecustomer_group_id
the function will stuck.
– mageDev0688
May 30 '17 at 12:26
add a comment |
But how I can get customer collection first? Could you please let me know complete process. I have created a block in my custom module to display the dropdown list.
– mageDev0688
May 30 '17 at 10:23
Please paste your code in question by editing it
– Kishan Patadia
May 30 '17 at 10:23
You can see the complete module code in this Question.
– mageDev0688
May 30 '17 at 10:26
After this I want to save these customer ID in custom table as well in respect of order id.
– mageDev0688
May 30 '17 at 10:29
please check the updated question. I have tried with your code->addFieldToFilter('customer_group_id','1');
, but when I use thecustomer_group_id
the function will stuck.
– mageDev0688
May 30 '17 at 12:26
But how I can get customer collection first? Could you please let me know complete process. I have created a block in my custom module to display the dropdown list.
– mageDev0688
May 30 '17 at 10:23
But how I can get customer collection first? Could you please let me know complete process. I have created a block in my custom module to display the dropdown list.
– mageDev0688
May 30 '17 at 10:23
Please paste your code in question by editing it
– Kishan Patadia
May 30 '17 at 10:23
Please paste your code in question by editing it
– Kishan Patadia
May 30 '17 at 10:23
You can see the complete module code in this Question.
– mageDev0688
May 30 '17 at 10:26
You can see the complete module code in this Question.
– mageDev0688
May 30 '17 at 10:26
After this I want to save these customer ID in custom table as well in respect of order id.
– mageDev0688
May 30 '17 at 10:29
After this I want to save these customer ID in custom table as well in respect of order id.
– mageDev0688
May 30 '17 at 10:29
please check the updated question. I have tried with your code
->addFieldToFilter('customer_group_id','1');
, but when I use the customer_group_id
the function will stuck.– mageDev0688
May 30 '17 at 12:26
please check the updated question. I have tried with your code
->addFieldToFilter('customer_group_id','1');
, but when I use the customer_group_id
the function will stuck.– mageDev0688
May 30 '17 at 12:26
add a comment |
protected $_customerCollectionFactory;
public function __construct(
MagentoFrameworkViewElementTemplateContext $context,
MagentoCustomerModelResourceModelCustomerCollectionFactory $customerCollectionFactory,
array $data =
)
{
$this->_context = $context;
$this->_customerCollectionFactory = $customerCollectionFactory;
parent::__construct($context, $data);
}
public function getCustomerCollection() {
$collection = $this->_customerCollectionFactory->create();
$collection->addFieldToFilter("group_id","3");
return $collection->getData();
}
add a comment |
protected $_customerCollectionFactory;
public function __construct(
MagentoFrameworkViewElementTemplateContext $context,
MagentoCustomerModelResourceModelCustomerCollectionFactory $customerCollectionFactory,
array $data =
)
{
$this->_context = $context;
$this->_customerCollectionFactory = $customerCollectionFactory;
parent::__construct($context, $data);
}
public function getCustomerCollection() {
$collection = $this->_customerCollectionFactory->create();
$collection->addFieldToFilter("group_id","3");
return $collection->getData();
}
add a comment |
protected $_customerCollectionFactory;
public function __construct(
MagentoFrameworkViewElementTemplateContext $context,
MagentoCustomerModelResourceModelCustomerCollectionFactory $customerCollectionFactory,
array $data =
)
{
$this->_context = $context;
$this->_customerCollectionFactory = $customerCollectionFactory;
parent::__construct($context, $data);
}
public function getCustomerCollection() {
$collection = $this->_customerCollectionFactory->create();
$collection->addFieldToFilter("group_id","3");
return $collection->getData();
}
protected $_customerCollectionFactory;
public function __construct(
MagentoFrameworkViewElementTemplateContext $context,
MagentoCustomerModelResourceModelCustomerCollectionFactory $customerCollectionFactory,
array $data =
)
{
$this->_context = $context;
$this->_customerCollectionFactory = $customerCollectionFactory;
parent::__construct($context, $data);
}
public function getCustomerCollection() {
$collection = $this->_customerCollectionFactory->create();
$collection->addFieldToFilter("group_id","3");
return $collection->getData();
}
answered Feb 12 '18 at 11:11
kaushik kumar roykaushik kumar roy
156
156
add a comment |
add a comment |
You can get customer group details and specific group member's customer ids by doing like this
class Trial extends MagentoFrameworkViewElementTemplate
{
protected $_customerGroup;
protected $_customerFactory;
public function __construct(
MagentoBackendBlockTemplateContext $context,
MagentoCustomerModelGroup $customerGroupCollection,
MagentoCustomerModelCustomerFactory $customerFactory,
array $data =
) {
$this->_customerGroupCollection = $customerGroupCollection;
$this->_customerFactory=$customerFactory;
parent::__construct($context, $data);
}
public function getCustomerGroup($currentGroupId)
{
//Get customer group Id , you have already this so directly get name
$collection = $this->_customerGroupCollection-
>load($currentGroupId);
echo $collection->getCustomerGroupCode();//Get group name
print_r($collection->getData());
}
public function getCustomer($customergroupId)
{
return $this->_customerFactory->create()->getCollection()-
>addFieldToFilter('group_id', $customergroupId);
}
}
add a comment |
You can get customer group details and specific group member's customer ids by doing like this
class Trial extends MagentoFrameworkViewElementTemplate
{
protected $_customerGroup;
protected $_customerFactory;
public function __construct(
MagentoBackendBlockTemplateContext $context,
MagentoCustomerModelGroup $customerGroupCollection,
MagentoCustomerModelCustomerFactory $customerFactory,
array $data =
) {
$this->_customerGroupCollection = $customerGroupCollection;
$this->_customerFactory=$customerFactory;
parent::__construct($context, $data);
}
public function getCustomerGroup($currentGroupId)
{
//Get customer group Id , you have already this so directly get name
$collection = $this->_customerGroupCollection-
>load($currentGroupId);
echo $collection->getCustomerGroupCode();//Get group name
print_r($collection->getData());
}
public function getCustomer($customergroupId)
{
return $this->_customerFactory->create()->getCollection()-
>addFieldToFilter('group_id', $customergroupId);
}
}
add a comment |
You can get customer group details and specific group member's customer ids by doing like this
class Trial extends MagentoFrameworkViewElementTemplate
{
protected $_customerGroup;
protected $_customerFactory;
public function __construct(
MagentoBackendBlockTemplateContext $context,
MagentoCustomerModelGroup $customerGroupCollection,
MagentoCustomerModelCustomerFactory $customerFactory,
array $data =
) {
$this->_customerGroupCollection = $customerGroupCollection;
$this->_customerFactory=$customerFactory;
parent::__construct($context, $data);
}
public function getCustomerGroup($currentGroupId)
{
//Get customer group Id , you have already this so directly get name
$collection = $this->_customerGroupCollection-
>load($currentGroupId);
echo $collection->getCustomerGroupCode();//Get group name
print_r($collection->getData());
}
public function getCustomer($customergroupId)
{
return $this->_customerFactory->create()->getCollection()-
>addFieldToFilter('group_id', $customergroupId);
}
}
You can get customer group details and specific group member's customer ids by doing like this
class Trial extends MagentoFrameworkViewElementTemplate
{
protected $_customerGroup;
protected $_customerFactory;
public function __construct(
MagentoBackendBlockTemplateContext $context,
MagentoCustomerModelGroup $customerGroupCollection,
MagentoCustomerModelCustomerFactory $customerFactory,
array $data =
) {
$this->_customerGroupCollection = $customerGroupCollection;
$this->_customerFactory=$customerFactory;
parent::__construct($context, $data);
}
public function getCustomerGroup($currentGroupId)
{
//Get customer group Id , you have already this so directly get name
$collection = $this->_customerGroupCollection-
>load($currentGroupId);
echo $collection->getCustomerGroupCode();//Get group name
print_r($collection->getData());
}
public function getCustomer($customergroupId)
{
return $this->_customerFactory->create()->getCollection()-
>addFieldToFilter('group_id', $customergroupId);
}
}
answered Apr 19 '18 at 4:22
SUBBULAKSHMI GSUBBULAKSHMI G
608
608
add a comment |
add a comment |
Thanks for contributing an answer to Magento Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f176607%2fmagento-2-get-specific-customer-group-customers-list%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown