2

I am working on to create custom attribute, While creating the attribute i need to add multiselect custom attribute option via code.

     $eavSetup->addAttribute(

            \Magento\Catalog\Model\Product::ENTITY,
            'c_bathrooms',/* Custom Attribute Code */
            [
                'group' => 'Product Details',/* Group name in which you want to display your custom attribute */
                'type' => 'text',/* Data type in which formate your value save in database*/
                'attribute_set' =>  'Chennai',
                'backend' => '',
                'frontend' => '',
                'label' => 'Bathrooms', /* lablel of your attribute*/
                'input' => 'multiselect',
                'class' => '',
                'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE,
                'visible' => true,
                'required' => false,
                'user_defined' => true,
                'default' => '',
                'searchable' => true,
                'filterable' => true,
                'comparable' => true,
                'visible_on_front' => true,
                'used_in_product_listing' => true,
                'unique' => false,
                'visible_in_advanced_search' => true,
                'filterable_in_search' => true,
                'option' => array('values' => array("1", "2","3","4","5","6"))

            ]
        );

i try to give option via code, that custom attrbute are created but our option only added in admin side and Default Sored view

reference:

reference image

i tried two ways:

  1. 'option' => array('values' => array("1", "2","3","4","5","6"))

  2. 'option' => [ 'values' => [ '1', '2', '3', '4', '5', '6' ] ]

The Above two methods created custom attribute with multiselect but only added option values in admin side not in Default stored view

Suggest me How to create custom attribute with option that option will add Admin and Default Store View in admin side.

Edit:

i need to add options to both places Admin and Default Store View

Reference:

enter image description here

I tried Options class way that also same result

http://webkul.com/blog/magento2-how-to-create-product-custom-attribute-from-installer-in-custom-module/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.