Breaking News
Home / Magento / Update Magento 2 Customer Programmitically

Update Magento 2 Customer Programmitically

Create a php file on you magento 2 root path and past this code. Now Type Localhost/your_file_name.php or domain/your_file_name.php. First we include app/bootstrap.php. now we can use magento 2 all functionality. Its inform to you, This is very unsecured and break the magento rules. use only if you must need this or Testing purpose.

use \Magento\Framework\App\Bootstrap;
$bootstrap = Bootstrap::create(BP, $_SERVER);
$objectManager = $bootstrap->getObjectManager();
$url = \Magento\Framework\App\ObjectManager::getInstance();
$storeManager = $url->get('\Magento\Store\Model\StoreManagerInterface');
$state = $objectManager->get('\Magento\Framework\App\State');
// Customer Factory to Create Customer

$websiteId = $storeManager->getWebsite()->getWebsiteId();
$store = $storeManager->getStore();  // Get Store ID
$storeId = $store->getStoreId();
// Instantiate object (this is the most important part)
$customerFactory = $objectManager->get('\Magento\Customer\Model\CustomerFactory'); 
$customer = $customerFactory->create();
if ($customer->getId()) {
    $customer = $customer->load($customerId); 
   // set store as 
   echo $customer->getPassword();
    try {

    } catch (Exception $ex) {
		echo 'wrong';
echo 'Create customer successfully'.$customer->getId();

Hits: 33

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.