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.

有帮助吗?

解决方案

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;
    }
许可以下: CC-BY-SA归因
scroll top