Hi All,
I'm trying to create multiple customers in single request api for this I have created small function with business logic.
When I request multiple customers to my custom api Error is came after creating first customer.
SpoilerError: Area code not set: Area code must be set before starting a session
SpoilerThis error is came magento-2 ver 1.0.0 , recently released MCE 1.0.0, MEE 1.0.0
**my code is:**
public function __construct(
CustomerRepository $customerRepository,
\Magento\Customer\Api\Data\CustomerInterface $customerInterface,
\Psr\Log\LoggerInterface $loggerInterface
){
$this->customerRepository = $customerRepository;
$this->_customerInterface = $customerInterface;
$this->_logger = $loggerInterface;
}
public function Customer_multiCreate(CustomInterface $customer){
$customer_data = array();
$customers = $customer->getCustomer();
for($i=0;$i<count($customers);$i++){
try
{
$email = "";
foreach($customers[$i] as $key => $val){
$field = 'set' . $key;
if($key == 'email')
$email = $val;
$this->_customerInterface->$field($val);
}
$customer_data[] = $this->customerRepository->save($this->_customerInterface);
}catch (\Exception $ex){
$this->_logger->info($ex->getMessage());
$customer_data[] = $this->customerRepository->get($email);
continue;
}
}
return $customer_data;
}