I am assuming that you have your custom column added in the database and custom field present on the admin company edit page in the General section.
- For reading the column value from the database into the field on the admin page:
Add in di.xml:
<!-- override core class in order to have the custom column show on the admin company edit page -->
<preference for="Magento\Company\Model\Company\DataProvider" type="MyVendor\MyModule\Model\Company\DataProvider" />
And in your DataProvider.php:
namespace MyVendor\MyModule\Model\Company;
class DataProvider extends \Magento\Company\Model\Company\DataProvider {
public function getGeneralData(\Magento\Company\Api\Data\CompanyInterface $company) {
$result = parent::getGeneralData($company);
# add custom column value to the General data section so that the value populates the custom field on the admin company edit page
$result['my_custom_column'] = $company->setMyCustomColumn();
return $result;
}
}
- For saving the field into the database custom column:
Add in di.xml:
<!-- override core class by plugin in order to save value from the admin company edit page into the custom column my_custom_column -->
<type name="Magento\Company\Model\CompanyRepository">
<plugin name="myvendor_mymodule_after_save_company" type="MyVendor\MyModule\Plugin\Model\CompanyRepository" />
</type>
And in your CompanyRepository.php:
namespace MyVendor\MyModule\Plugin\Model;
class CompanyRepository {
public function afterSave(\Magento\Company\Model\CompanyRepository $companyRepository, \Magento\Company\Api\Data\CompanyInterface $company) {
$my_custom_column = 'some value here';
$company->setMyCustomColumn($my_custom_column);
$company->save();
return $company;
}
}