In B2B, Magento 2 You can fetch a list of customer company extension attributes by customer id.
Company module contains customer extension attributes that are mapped to the Customer module in Magento core code.
List of Customer company extension attributes,
- company_id
- job_title
- status
- telephone
Check the Magento code to get customer company extension attributes,
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | <?php namespace Package\Modulename\Model; use Magento\Company\Api\Data\CompanyInterface; use Magento\Framework\Exception\LocalizedException; use Magento\Customer\Api\CustomerRepositoryInterface; use Magento\Company\Api\Data\CompanyCustomerInterface; use Magento\Framework\Exception\NoSuchEntityException; class CompanyExtensionAttribute { /** * @var CompanyCustomerInterface */ private $customerAttributes; /** * @var CustomerRepositoryInterface */ private $customerRepository; public function __construct( CustomerRepositoryInterface $customerRepository ) { $this->customerRepository = $customerRepository; } /** * Get customer extension attributes * * @return CompanyCustomerInterface|null * @throws NoSuchEntityException * @throws LocalizedException */ public function getCustomerAttributes() { $customerId = 10; // pass customer id if (!$this->customerAttributes && $customerId) { $this->customerAttributes = $this->customerRepository->getById($customerId) ->getExtensionAttributes()->getCompanyAttributes(); } return $this->customerAttributes; } |
Now you can fetch any customer company extension attribute using below code,
1 2 3 4 5 | <?php $jobTitle = ''; if ($this->getCustomerAttributes()) { $jobTitle = $this->getCustomerAttributes()->getJobTitle(); } |
You can fetch telephone, status and company id using the above way.