I want to get collection for customer website wise. I have a website id, and now I want all the customers which belong to that particular website id.

I am trying here:

using \Magento\Customer\Model\ResourceModel\Customer\CollectionFactory $customerFactory

$customers = $this->_customerFactory->create();             

foreach($customers as $customer)

How can I get collection website wise?

  • 1
    what have you tried? just add a filter for website_id – Philipp Sander Dec 17 '18 at 12:17

We can get collection website wise using below code:

protected $_customerFactory;

\Magento\Customer\Model\CustomerFactory $customerFactory

$this->_customerFactory = $customerFactory;

$customers = $this->_customerFactory->create()->getCollection()
                  ->addAttributeToFilter("website_id", array("eq" => $websiteId));              

foreach($customers as $customer)
  • I believe this line $this->_customerFactory->create()->getCollection() without any filter loads all the customers in the database, is that right? – cnu Jan 15 at 0:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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