1

I am using customer repository interface, to fetch some values, of the customer.

I have added a custom attribute "Authnet_Account_Number".

I am trying to fetch the value of it by,

$customer = $this->_customerRepository->getById($customerId);
$authnetAccountNumber = $customer->getCustomAttribute("authnet_account_number");

But when I print $authnetAccountNumber,

it is showing value "object"

4

you can get Value of attribute by getValue function

$customer = $this->_customerRepository->getById($customerId);
$customer->getCustomAttribute('authnet_account_number')->getValue(); 

$customer->getCustomAttribute('authnet_account_number') is always have object in return

i am sure it will work for you.

1

See also using getCustomAttribute which is not recommended

Instead try

$authnetAccountNumber = $customer->getData('authnet_account_number');
// or
$authnetAccountNumber = $customer->getAuthnetAccountNumber();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.