Using csv we can update customer ids
use this code in controller
if (($handle = fopen("/chroot/home/*****/*********/html/app/code/Test/Testmodule/Controller/Index/uniqueorder.csv", "r")) !== FALSE) {
while (($data = fgetcsv($handle, 10000, ",")) !== FALSE) {
$email = $data[2];
// echo $url;die("data");
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$orderCollection = $objectManager->create('\Magento\Sales\Model\ResourceModel\Order\CollectionFactory');
$collection = $orderCollection->create()
->addAttributeToSelect('*')
->load();
foreach ($collection as $order) {
if ($order->getCustomerId() != NULL && $order->getCustomerEmail() == $email) {
$customerData = $objectManager->create('Magento\Customer\Model\Customer')->loadByEmail($email);
$customerId = $customerData->getId();
$order->setCustomerId($customerId);
$order->save();
echo '<pre>';
print_r($customerData->getId() . "--------" . $order->getCustomerId() . "------" . $customerData->getEmail() . '-----------' . $order->getCustomerEmail()."----------". $order->getIncrementId());
} else {
// $customerData = $objectManager->create('Magento\Customer\Model\Customer')->loadByEmail($email);
// $customerId = $currentproduct->getId();
//
//
// echo '<pre>';
// print_r($customerData->getId() . "--------" . $order->getCustomerId() . "------" . $customerData->getEmail().'-----------'.$order->getCustomerEmail());
// die("data");
// echo $order->getIncrementId() . "----------------" . $order->getCustomerEmail() . "<br/>";
}
}
}
}
use this code in controller
if (($handle = fopen("/chroot/home/*****/*********/html/app/code/Test/Testmodule/Controller/Index/uniqueorder.csv", "r")) !== FALSE) {
while (($data = fgetcsv($handle, 10000, ",")) !== FALSE) {
$email = $data[2];
// echo $url;die("data");
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$orderCollection = $objectManager->create('\Magento\Sales\Model\ResourceModel\Order\CollectionFactory');
$collection = $orderCollection->create()
->addAttributeToSelect('*')
->load();
foreach ($collection as $order) {
if ($order->getCustomerId() != NULL && $order->getCustomerEmail() == $email) {
$customerData = $objectManager->create('Magento\Customer\Model\Customer')->loadByEmail($email);
$customerId = $customerData->getId();
$order->setCustomerId($customerId);
$order->save();
echo '<pre>';
print_r($customerData->getId() . "--------" . $order->getCustomerId() . "------" . $customerData->getEmail() . '-----------' . $order->getCustomerEmail()."----------". $order->getIncrementId());
} else {
// $customerData = $objectManager->create('Magento\Customer\Model\Customer')->loadByEmail($email);
// $customerId = $currentproduct->getId();
//
//
// echo '<pre>';
// print_r($customerData->getId() . "--------" . $order->getCustomerId() . "------" . $customerData->getEmail().'-----------'.$order->getCustomerEmail());
// die("data");
// echo $order->getIncrementId() . "----------------" . $order->getCustomerEmail() . "<br/>";
}
}
}
}
Comments
Post a Comment