I have created a custom customer select attribute (drop down). See below code.
public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
{
$eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);
$attributeCode = 'custom_currency';
$eavSetup->addAttribute(CustomerMetadataInterface::ENTITY_TYPE_CUSTOMER, $attributeCode, [
'type'=> 'varchar',
'label' => 'Custom Currency',
'input' => 'select',
'source' => 'Magento\Eav\Model\Entity\Attribute\Source\Table',
'required' => 0,
'visible' => 1,
'user_defined' => 1,
'system' => 0,
'position' => 120,
'option' =>
array(
'values' =>
array(
0 => 'EUR',
1 => 'CHF',
2 => 'CZK',
3 => 'PLN',
4 => 'DKK',
5 => 'NOK',
6 => 'SEK',
7 => 'GBP',
8 => 'USD',
)
)
]);
$eavSetup->addAttributeToSet(
CustomerMetadataInterface::ENTITY_TYPE_CUSTOMER,
CustomerMetadataInterface::ATTRIBUTE_SET_ID_CUSTOMER,
null,
$attributeCode
);
$attribute = $this->eavConfig->getAttribute(CustomerMetadataInterface::ENTITY_TYPE_CUSTOMER, $attributeCode);
$attribute->setData('used_in_forms', [
'adminhtml_customer',
]);
$attribute->getResource()->save($attribute);
}
In my Observer where I get my customer data I want to get the option value of this attribute too.
$customer = $observer->getCustomer();
$customCurrency = $customer->getCustomCurrency();
The code above only works when my attribute is an input field but not when its a select attribute, can anyone help?