cancel
Showing results for 
Search instead for 
Did you mean: 

Get Company Collection via Interface Repository B2B Magento 2.

SOLVED

Get Company Collection via Interface Repository B2B Magento 2.

How to get Company Collection in B2B Magento 2?

If Issue Solved, Click Kudos/Accept As solutions. Get Magento insight from
Magento 2 Blogs/Tutorial
1 ACCEPTED SOLUTION

Accepted Solutions

Re: Get Company Collection via Interface Repository B2B Magento 2.

You can get Company Collection in Magento 2 By 

Magento\Company\Api\CompanyRepositoryInterface Interface.

 

CompanyRepositoryInterface contains useful function like Get, Save, Delete and GetList and DeleteById.

 

You can get List of Company Collection in B2B Magento by below way,

 

 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;
    }

Now Iterate the loop and Get Company Details,

$getCompany = $this->getCompanyList();
foreach($getCompany as $company) {
    echo $company->getCompanyName();
echo $company->getLegalName(); }

Check More details for Company Collection, https://www.rakeshjesadiya.com/get-company-collection-in-magento-2-b2b/

 

If Issue Solved, Click Kudos/Accept As solutions. Get Magento insight from
Magento 2 Blogs/Tutorial

View solution in original post

2 REPLIES 2

Re: Get Company Collection via Interface Repository B2B Magento 2.

You can get Company Collection in Magento 2 By 

Magento\Company\Api\CompanyRepositoryInterface Interface.

 

CompanyRepositoryInterface contains useful function like Get, Save, Delete and GetList and DeleteById.

 

You can get List of Company Collection in B2B Magento by below way,

 

 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;
    }

Now Iterate the loop and Get Company Details,

$getCompany = $this->getCompanyList();
foreach($getCompany as $company) {
    echo $company->getCompanyName();
echo $company->getLegalName(); }

Check More details for Company Collection, https://www.rakeshjesadiya.com/get-company-collection-in-magento-2-b2b/

 

If Issue Solved, Click Kudos/Accept As solutions. Get Magento insight from
Magento 2 Blogs/Tutorial

Re: Get Company Collection via Interface Repository B2B Magento 2.

Hi @Rakesh Jesadiya 

How we can search in company collection? like full text search
Looking forward to hear from you.

Thanks,
Rahul