0

I can load in controller with:

\Magento\Customer\Api\CustomerRepositoryInterface $customerRepositoryInterface,

as:

$customer = $this->_customerRepositoryInterface->getById(1);

and using CustomerFactory:

\Magento\Customer\Model\CustomerFactory $customerFactory,

as:

$customer=$this->_customerFactory->create();
        $customer->setWebsiteId(1);
        $customer->load(1);
        $data= $customer->getData();
        print_r($data);exit;

But both of them are not working in Model/MyClass and Helper/Myclass

Errors is

Fatal error: Uncaught Error: Call to a member function getById() on null

Please mention the missing or other way!!

Update

Here is my full constructor for this class:

public function __construct(
\Magento\Customer\Model\Customer $customerModel,
\Magento\Customer\Model\CustomerFactory $customerFac,
\Zend\Http\Client $zendClient,
\Magento\Customer\Model\Session $customerSession,
\Magento\Store\Model\StoreManagerInterface $storeManager,
\Magento\Customer\Api\CustomerRepositoryInterface $customerRepositoryInterface,
\Magento\Customer\Api\AddressRepositoryInterface $addressRepositoryInterface,
\Magento\Customer\Model\Group $customerGroupCollection,
\Magento\Customer\Model\ResourceModel\CustomerFactory $customerFactory) {
    $this->customerModel = $customerModel;
    $this->customerFactory = $customerFactory;
    $this->zendClient = $zendClient;
    $this->_storeManager = $storeManager;
    $this->_customerFac = $customerFac;
    $this->_customerSession = $customerSession;
    $this->_customerRepositoryInterface = $customerRepositoryInterface;
    $this->_customerGroupCollection = $customerGroupCollection;
    $this->_addressRepositoryInterface = $addressRepositoryInterface;
}
  • 1
    Show your __construct. – Sohel Rana Jun 29 at 16:18
  • @SohelRana I added the constructor – Ajwad Syed Jun 30 at 6:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.