Get customer data from id - magento2

bala.skpm picture bala.skpm · Feb 24, 2016 · Viewed 37.4k times · Source

how can we get the customer data from id not from customer session in Magento2.

Kindly let me know.

Answer

CarComp picture CarComp · Nov 15, 2016

Load the customer by using the api factory. This is the correct way.

<?php

namespace Yourcompany\Customer\Helper {

/**
 * Eav data helper
 */
class Data extends \Magento\Framework\App\Helper\AbstractHelper
{
    protected $customerRepository;

    public function __construct(
        \Magento\Customer\Api\CustomerRepositoryInterfaceFactory $customerRepositoryFactory) {
        $this->customerRepository = $customerRepositoryFactory->create();
    }

    public function LoadCustomerById($customerId) {
         $cst = $this->customerRepository->getById($customerId);
         return $cst;
    } 

}

?>