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!
1 Answer 1
Try This :-
print_r($customers->getCustomAttributes('enable_alerts')->getValue());
-
Is there a way to filter the customer by custom attributes values ??Ghulam.M– Ghulam.M2019年06月19日 07:37:37 +00:00Commented Jun 19, 2019 at 7:37
-
yes you can use addAttributeToFilter to filter dataRonak Rathod– Ronak Rathod2019年06月19日 07:38:40 +00:00Commented Jun 19, 2019 at 7:38
-
Sorry to ask is there a way I can update current custom attribute value?? :)Ghulam.M– Ghulam.M2019年06月19日 11:48:58 +00:00Commented Jun 19, 2019 at 11:48
-
yes you can setRonak Rathod– Ronak Rathod2019年06月19日 11:53:07 +00:00Commented Jun 19, 2019 at 11:53
-
could you please share howGhulam.M– Ghulam.M2019年06月19日 11:54:25 +00:00Commented Jun 19, 2019 at 11:54
Explore related questions
See similar questions with these tags.