I want to create a company programmatically from a standalone script. Can someone please help me out with this. how can I create it.
Here is the code I am using to create company.
$companyRepo = $obj->create('Magento\Company\Api\CompanyRepositoryInterface');
$companyObj = $obj->create('\Magento\Company\Api\Data\CompanyInterface');
$dataObj = $obj->create('\Magento\Framework\Api\DataObjectHelper');
$data = [
'company_name' => [
'Test Company'
],
'company_email' => '[email protected]',
'status' => '1',
'street' => ['test','test2'],
'city' => 'test city',
'postcode' => '12345',
'country_id' => 'US',
'firstname' => 'test f',
'lastname' => 'test l',
'email' => '[email protected]',
'customer_group_id' => 1,
'website_id' => 1
];
$dataObj->populateWithArray(
$companyObj,
$data,
\Magento\Company\Api\Data\CompanyInterface::class
);
$companyRepo->save($companyObj);
But it is throwing below error.
EXCEPTION::#0 /var/www/html/project/vendor/magento/module-company/Model/Company/Save.php(79): Magento\Company\Model\SaveValidatorPool->execute(Object(Magento\Company\Model\Company\Interceptor), Object(Magento\Company\Model\Company\Interceptor))
Thanks in advance!
Magento\Company\Model\CompanyFactory::create
instead of using the data helper. Or debuggingSaveValidatorPool
what exactly is wrong there.