Magento 2, Customer module have comes with extension attributes, getVertexCustomerCode( ) and getIsSubscribed( ).
If you have created your customer extension attributes and you want to fetch customer extension attributes value using Customer Object, You need to first get Customer Object and based on Customer object you can find your custom extension attributes value.
Code Demo,
<?php public function __construct( \Magento\Customer\Api\CustomerRepositoryInterface $customerRepository ) { $this->customerRepository = $customerRepository; } public function getCustomerExtensionAttribute() { $customerId = 1; // Your Customer Id $customer = $this->customerRepository->getById($customerId); $extensionAttributes = $customer->getExtensionAttributes(); echo $isSubscribed = $extensionAttributes->getIsSubscribed(); // bool echo $getVertexCustomerCode = $extensionAttributes->getVertexCustomerCode(); // display vertex code if set }
print_r(get_class_methods($extensionAttribute));
Array ( [0] => getIsSubscribed [1] => setIsSubscribed [2] => getVertexCustomerCode [3] => setVertexCustomerCode [4] => __construct [5] => setData [6] => __toArray )
You can get result of all the Customer Extension Attributes in above array.
Using the above function, you can get the value of vertex customer code and is subscribed() value of customer object.