3

How to get all customer data using object manager.

Actually, I have created root file and load customer data with specific id but I want to load all customer data not a specific customer id.

What i have tried

 <?php use Magento\Framework\App\Bootstrap; require __DIR__ . '/app/bootstrap.php'; $bootstrap = Bootstrap::create(BP, $_SERVER); $obj = $bootstrap->getObjectManager(); $storeManager = $obj->get('\Magento\Store\Model\StoreManagerInterface'); $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $appState = $objectManager->get('\Magento\Framework\App\State'); $appState->setAreaCode('frontend'); $customerID = 10; $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $customerObj = $objectManager->create('Magento\Customer\Model\Customer') ->load($customerID); $customerEmail = $customerObj->getEmail(); print_r($customerEmail); ?> 

It is working but i only can get data from specific customer id.so how to get customer data of all customer id.

0

2 Answers 2

5
<?php use Magento\Framework\App\Bootstrap; require __DIR__ . '/app/bootstrap.php'; $bootstrap = Bootstrap::create(BP, $_SERVER); $obj = $bootstrap->getObjectManager(); $storeManager = $obj->get('\Magento\Store\Model\StoreManagerInterface'); $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $appState = $objectManager->get('\Magento\Framework\App\State'); $appState->setAreaCode('frontend'); $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $customerObj = $objectManager->create('Magento\Customer\Model\Customer')->getCollection(); foreach($customerObj as $customerObjdata ) { echo "<pre/>"; print_r($customerObjdata ->getData()); } 
0
-1

This one will help full for you to get all customers,

<?php use Magento\Framework\App\Bootstrap; require __DIR__ . '/app/bootstrap.php'; $bootstrap = Bootstrap::create(BP, $_SERVER); $obj = $bootstrap->getObjectManager(); $storeManager = $obj->get('\Magento\Store\Model\StoreManagerInterface'); $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $appState = $objectManager->get('\Magento\Framework\App\State'); $appState->setAreaCode('frontend'); $customerID = 1; $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $customerObj = $objectManager->create('Magento\Customer\Model\Customer') ->getCollection()->getData(); echo "<pre>"; print_r($customerObj); ?> 
1
  • 1
    $customerID = 1 does nothing here. This is the same as the accepted answer with that extra useless $customerID thrown in. Commented Aug 2, 2018 at 15:26

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.