How to get Company Collection in B2B Magento 2?
Solved! Go to Solution.
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/
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/
Hi @Rakesh Jesadiya
How we can search in company collection? like full text search
Looking forward to hear from you.
Thanks,
Rahul