Get Company Collection programmatically in Magento 2 B2B.

Magento Commerce has a native B2B feature. If you are using B2B feature for your store from Magento Commerce, You can get a list of the company for your store from Backend by Navigating to Customer -> Companies

When you store runs on B2B mechanism, You have many companies assigned to a store for your Business.

Magento\Company\Api\CompanyRepositoryInterface Interface will be used for getting list of Company collection.

When you click on Company link, You can see a list of the available company for your store.

You can get Company Collection programmatically by below way,

<?php
class YourClass {
    public function __construct(
        \Magento\Company\Api\CompanyRepositoryInterface $companyRepository,
        \Magento\Framework\Api\SearchCriteriaBuilder $searchCriteriaBuilder
    ) {
        $this->companyRepository = $companyRepository;
        $this->searchCriteriaBuilder = $searchCriteriaBuilder;
    }

    public function getCompanyList()
    {
        $searchCriteria = $this->searchCriteriaBuilder->create();
        $companyList = $this->companyRepository->getList($searchCriteria)->getItems();
        return $companyList;
    }
}

Get a list of company information from a template file,

$getCompany = $this->getCompanyList();
foreach($getCompany as $company) {
    echo $company->getCompanyName();echo "<br>";
    echo $company->getLegalName();echo "<br>";
    echo $company->getCompanyEmail();echo "<br>";
    echo $company->getCity();echo "<br>";
    echo $company->getTelephone();echo "<br>";
}