cancel
Showing results for 
Search instead for 
Did you mean: 

Custom Customer Attribute filter on search criteria Magento 2.1.8

SOLVED
   Did you know you can see the translated content as per your choice?

Translation is in progress. Please check again after few minutes.

Custom Customer Attribute filter on search criteria Magento 2.1.8

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();

1 ACCEPTED SOLUTION

Accepted Solutions

Re: Custom Customer Attribute filter on search criteria Magento 2.1.8

It is working fine, sorry its was my variable and customers data which is not exist that is why its returning 0 exception.

 

View solution in original post

2 REPLIES 2

Re: Custom Customer Attribute filter on search criteria Magento 2.1.8

It is working fine, sorry its was my variable and customers data which is not exist that is why its returning 0 exception.

 

Re: Custom Customer Attribute filter on search criteria Magento 2.1.8

@Agarwal Aman  Did you get any solutions ? I have same issue with my product interface.  Please help if you get any alternate solutions or anything.