0

I am trying to fetch a custom attribute value of a customer in magento 2 but I am unable to fetch it

I am using \Magento\Customer\Api\CustomerRepositoryInterface class to fetch the custom customer attribute of a customer

I have tried this

 $customers = $this->customerRepositoryInterface->getById(2);
 print_r($customers->getCustomAttributes('enable_alerts'));

This returns

Array (
 [enable_alerts] => Magento\Framework\Api\AttributeValue Object
 (
 [_data:protected] => Array
 (
 [attribute_code] => enable_alerts
 [value] => 1
 )
 )
)

But I need only value of enable_alerts. What I am doing wrong here Is there any other way of fetching customers attribute value I have tried multiple codes and searched every thing!

SantiBM
1,39015 silver badges31 bronze badges
asked Jun 18, 2019 at 13:50

1 Answer 1

0

Try This :-

print_r($customers->getCustomAttributes('enable_alerts')->getValue());
answered Jun 18, 2019 at 14:26
7
  • Is there a way to filter the customer by custom attributes values ?? Commented Jun 19, 2019 at 7:37
  • yes you can use addAttributeToFilter to filter data Commented Jun 19, 2019 at 7:38
  • Sorry to ask is there a way I can update current custom attribute value?? :) Commented Jun 19, 2019 at 11:48
  • yes you can set Commented Jun 19, 2019 at 11:53
  • could you please share how Commented Jun 19, 2019 at 11:54

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.