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
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. – seanbreeden Aug 2 '18 at 15:26

Your Answer

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

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