Get Company Data by company id in B2B Magento 2.

You can get company data by company id in the B2B version of Magento Commerce or Magento Cloud Edition.

Get company data using B2B, You must install B2B extension first to get data of a company,

<?php
use Magento\Company\Api\CompanyRepositoryInterface;

class Company
{

    public function __construct(
        CompanyRepositoryInterface $companyRepository
    ) {
        $this->companyRepository = $companyRepository;
    }

    public function getCompanyData()
    {
	$company = null;
        $companyId = 3;
        try {
            $company = $this->companyRepository->get($companyId);
        } catch (\Exception $e) {
            throw new Exception("Error Processing Request", $e->getMessage());
        }
        return $company;
    }
}

Output:

Array
(
    [entity_id] => 3
    [status] => 1
    [company_name] => ztech
    [legal_name] => Rbj
    [company_email] => rakesh@example.com
    [street] => 200 E. 6th Street
    [city] => Austin
    [country_id] => US
    [region_id] => 57
    [postcode] => 78701
    [telephone] => 1234554321
    [customer_group_id] => 1
    [sales_representative_id] => 1
    [super_user_id] => 31
)

 

Get Shared Catalog data by Customer group id programmatically magento 2.

Shared Catalog is the native functionality of B2B Magento Commerce. Magento gives you the ability to maintain shared catalogs with the custom pricing structure for different companies. A Public Default(General) Catalog will be available native with Magento B2B.

You can get Shared Catalog data by Customer group id programmatically using
Magento\SharedCatalog\Api\SharedCatalogRepositoryInterface.
Interface used to get, delete and save catalog data related stuff.

Get Shared Catalog Data by id Magento 2 B2B

You need to filter customer_group_id using SearchCriteriaBuilder Interface and assigned searchCriteria object to sharedCatalogRepository getList() method. Continue reading “Get Shared Catalog data by Customer group id programmatically magento 2.”

Assign customer to company Magento 2 B2B.

You can add Customer to Company Programmatically by assignCustomer( ) function from CompanyManagementInterface.

Magento\Company\Api\CompanyManagementInterface Interface will be used for assign customer to Company in Magento 2.

You need Company id and Customer id to achieve this. Continue reading “Assign customer to company Magento 2 B2B.”