<?php
ob_start();
use Magento\Framework\App\Bootstrap;
require __DIR__ . '/app/bootstrap.php';
$store_id = 1;
$csv_filepath = "subscribers.csv";
$csv_delimiter = ',';
$csv_enclosure = '"';
$magento_path = __DIR__;
$params = $_SERVER;
$bootstrap = Bootstrap::create(BP, $params);
$obj = $bootstrap->getObjectManager();
$state = $obj->get('Magento\Framework\App\State');
$state->setAreaCode('frontend');
$websiteId = $obj->get('Magento\Store\Model\StoreManagerInterface')
->getStore()
->getWebsiteId();
$customerAccountManagement =$obj
->create('Magento\Customer\Api\AccountManagementInterface');
$_subscriberFactory = $obj->create('Magento\Newsletter\Model\SubscriberFactory');
if (($handle = fopen("subscribers-import.csv", "r")) !== FALSE) {
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
// email Id
$emailId = $data[1];
/* customer */
if($customerAccountManagement->isEmailAvailable($emailId , $websiteId)){
echo $emailId ."Guest <br"<br/>";
$_subscriberFactory = $_subscriberFactory->create()->subscribe($emailId );
}else{
echo $emailId ."Register <br/>";
$customerFactory = $obj->get('Magento\Customer\Model\CustomerFactory');
$customer=$customerFactory->create();
$customer->setWebsiteId($websiteId);
$customer->loadByEmail($emailId );// load customer by email address
if($customer->getId()){
$_subscriberFactory->create()->subscribeCustomerById($customer->getId());
}
}
}
fclose($handle);
}
ob_end_flush();
?>
lht@gmail.comGuestcom
4337@icloud.comGuestcom
Fatal error: Uncaught Error: Call to a member function create() on integer in /home/xyz/dev.xyz.com/import.php:37 Stack trace: #0 {main} thrown in /home/xyz/dev.xyz.com/import.php on line 37
it seems to be adding a Guest to the end of the email ID, andits not importing the subscriber names, type, nor the correct website, store or store view.