Skip to content

New: Magento 2 extensions are coming soon, with early access open now.Request early access

Jigar Karangiya

Get Company Admin using company ID programmatically Magento 2 B2B

JK
Jigar Karangiya
· 1 min read
Get Company Admin using company ID programmatically Magento 2 B2B

You can get Company admin Programmatically by getAdminByCompanyId( ) function from CompanyManagementInterface.

Magento\Company\Api\CompanyManagementInterface Interface will be used to get Company Admin-related data from the Company in Magento 2.

You need a Company id to achieve this.

You can get assigned a company admin details programmatically by the below way,

php
<?php
 
class YourClass {
 
    public function __construct(
        \Magento\Company\Api\CompanyManagementInterface $companyRepository
    ) {
        $this->companyRepository = $companyRepository;
    }
 
    public function getAdminByCompanyId()
    {
        $companyId = 39;
        $companyAdmin = $this->companyRepository->getAdminByCompanyId($companyId);
        //echo $companyAdmin->getId();
        return $companyAdmin;
    }
}

Using this way you can get the customer object of the company admin associated with a particular company id.

I hope this tutorial is helpful. Happy Coding !!

Customer Group Catalog for Magento 2

Show each customer group its own catalog. Coming soon from Jigar Karangiya.
Request Early Access

Written by Jigar Karangiya, Adobe Commerce Consultant.

More about me

Related posts