0

I'm trying to make a 3 value select attribut in the customer edit page in admin. The attribut is created in DB after setup:upgrade but stored in eav_attribute_option table as follow :

enter image description here

the value sent in post request when editing a customer is the option_id not the values set in the InstallData.php

'label' => 'My Label',
'type' => 'varchar',
'input' => 'select',
'source' => 'Magento\Eav\Model\Entity\Attribute\Source\Table',
'position' => 1001,
'visible' => true,
'required' => false,
'is_used_in_grid' => true,
'is_visible_in_grid' => true,
'is_filterable_in_grid' => true,
'system' => 0,
'user_defined' => true,
'option' => [
    'values' => [
        0 => 'Default',
        1 => 'No',
        2 => 'Yes',
    ]
]

Labels are shown correctly in admin but not their values.

enter image description here

I suspect source, and trying int instead of varchar produced an error.

1

Check this link

the above link is creating one attribute, you need to add a different source to provide your custom options value. check line 29

'source' => 'W3solver\Customcategorymode\Model\Category\Attribute\Source\Showmode',

then create the source file and add code

public function getAllOptions()
    {
        if (!$this->_options) {
            $this->_options = [
                ['value' => 1, 'label' => __('No')],
                ['value' => 2, 'label' => __('Yes')],
            ];
        }
        return $this->_options;
    }
1
  • wasn't working at first because I deleted 'system' => 0, line, Thank you !
    – medmek
    Apr 24 '17 at 9:24

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.