1

I know I can do the following

    $customerId = 1;
    $customer = $this->customerRepositoryInterface->getById($customerId);
    $code = $customer->getCustomAttribute('attribute_code')->getValue();

But as the attribute is a type of "select" and not "text", it gives me the ID as the value and not the actual label

Therefore how do I get the label/frontend name of the option instead of the ID

0

You might need to load the attribute using the AttributeRepositoryInterface::get($entityTypeCode, $attributeCode).

This will return an AttributeInterface on which you can call getOptions().

This will return an AttributeOptionInterface[]

Each AttributeOptionInterface exposes getLabel() and getValue().

What you are left with is a search problem.

Also as this is a custom attribute you(or who added the attribute) in a DataPatch or InstallScript, probably already specified the options for it. From that Option class you can extract your label based on your value.

| improve this answer | |

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.