Magento 2 - Customer address custom attribute option label from value
-
15-04-2021 - |
سؤال
I am using Magento 2.2.8 Enterprise Edition
I have a custom address attribute area a dropdown attribute with multiple options.
Now when I am getting value of attribute by using this code, I am getting ID
$address->getCustomAttribute('area')->getValue();
I just want to get Label of the selected area option, can anyone tell me How can I get it?
المحلول
Load eavConfig via dependency Injection.
protected $eavConfig;
public function __construct(
\Magento\Eav\Model\Config $eavConfig,
)
{
$this->eavConfig = $eavConfig;
}
Than you can get the label like this.
$attribute = $this->eavConfig->getAttribute('customer_address', "attribute_code");
$optionlabel = $attribute->getSource()->getOptionText($attributeValue);
لا تنتمي إلى magento.stackexchange