0

I am trying to get customer collection based on email_id and my custom customer attributes i.e phone_code and mobile_number.

When I only add email filter getList return's customer array object but when I add my custom filter of mobile_number and phone_code attribute it return's 0 element error.

So is there any way we can use custom customer attributes in Search Criteria.

My Sample code:

$customerRepository = $this->_customerRepositoryInterface;

$email[] = $this->_filterBuilder
->setField('email')
->setValue($row[5])
->setConditionType('eq')
->create();
$phonecode[] = $this->_filterBuilder
->setField('phone_code')
->setValue($row[7])
->setConditionType('eq')
->create();
$mobile[] = $this->_filterBuilder
->setField('mobile_number')
->setValue($row[11])
->setConditionType('eq')
->create();

$searchCriteria = $this->_searchCriteriaBuilder
->addFilters($email)
->addFilters($phonecode)
->addFilters($mobile) 
->create(); 

$customerCollection = $customerRepository->getList($searchCriteria)->getItems();
3
  • what's in $row array ? Sep 27, 2017 at 14:52
  • it is just some value you can assume $row[5]="[email protected]", $row[7]="65" and $row[11]="00000110" Sep 28, 2017 at 1:19
  • Hi All, It's working fine now, it was because of my data was not correctly saved for particular customer. Thanks. Sep 28, 2017 at 2:27

0

Your Answer

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