5

I need to get customer id before login by custom attribute value in Magento 2.1.5, for login by username.

$this->customerRepository->get($username);

1 Answer 1

5

Please Try below code :

    $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
    $customerObj = $objectManager->create('Magento\Customer\Model\ResourceModel\Customer\Collection');
    $collection = $customerObj->addAttributeToSelect('*')
                  ->addAttributeToFilter('your_attribute_name',$your_attribute_value)
                  ->load();
            
   $c_data=$collection->getData();
   $c_data[0]['entity_id'];
   echo $c_data[0]['entity_id']; 
5
  • @Bapu I have updated my answer please check. Commented May 1, 2017 at 9:13
  • Thanx deexit & manthan too Commented May 1, 2017 at 9:36
  • Before login it secure or not? Commented May 1, 2017 at 9:37
  • How we can get customer attribute collection in magento 2? Because i want to show on catalog price rule form. How i can achieve this? Commented Aug 3, 2017 at 7:03
  • It always displays first record...seems it holds first record. Commented Aug 6, 2020 at 11:19

Your Answer

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

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