1

I have customer entity id, how do i get customer attribute value by loading customer entity id, Please provide me a solution

2 Answers 2

6

you can use this code to get customer attribute value.

class MyClass 
    {
        protected $_customer;
        protected $_customerFactory;

        public function __construct(...
               \Magento\Customer\Model\CustomerFactory $customerFactory,
               \Magento\Customer\Model\Customer $customers
        )
        {
            ...
            $this->_customerFactory = $customerFactory;
            $this->_customer = $customers;
        }

        public function getCustomerCollection() {
            return $this->_customer->getCollection()
                   ->addAttributeToSelect("*")
                   ->load();
        }

        public function getFilteredCustomerCollection() {
            return $this->_customerFactory->create()->getCollection()
                    ->addAttributeToSelect("*")
                    ->addAttributeToFilter("firstname", array("eq" => "Max"))
                    -load();
        }
    }
0

That depends where you want that information, template, some module etc. you can use below code to get customer object data :

$id = xxx; // customer id
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$customerObj = $objectManager->create('Magento\Customer\Model\Customer')
        ->load($id);
$customerFirstName = $customerObj->getFirstName();

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.