3

I am creating custom Product Attribute Of type MULTI SELECT,

I want to create different option label for each stores for this particular Attribute,

I have tried with this below code,

$eavSetup->addAttribute(
            \Magento\Catalog\Model\Product::ENTITY,
            'myattribute',
            [
                'type' => 'text',
                'backend' => 'Magento\Eav\Model\Entity\Attribute\Backend\ArrayBackend',
                'frontend' => '',
                'label' => 'My Attribute',
                'input' => 'multiselect',
                'class' => '',
                'option' => ['values' => 
                                [
                                    '0' => '1',
                                    '1' => '2',
                                    '2' => '3',
                                    '3' => '4',
                                    '4' => '5',
                                    '5' => '6',
                                ],
                            ],  // I have tried this way but not working
                'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE,
                'visible' => true,
                'required' => false,
                'user_defined' => true,
                'default' => '',
                'searchable' => false,
                'filterable' => false,
                'comparable' => false,
                'visible_on_front' => false,
                'used_in_product_listing' => true,
                'wysiwyg_enabled' => true,
                'unique' => false,
                'apply_to' => ''
            ]
        );

With the above code, Attribute Options were inserted as a new row & I want it to be stored as store wise.

How can I achieve this thing.?

4

I have check the core how magento install the label and I found code in below file

vendor/magento/module-eav/Setup/EavSetup.php

in this file I got addAttributeOption method.

After seeing the code I got your answer, create attribute like below

You can create multiselect and dropdown attribute option label different on store basis like below

$eavSetup->addAttribute(
        \Magento\Catalog\Model\Product::ENTITY,
        'myattribute',
        [
            'type' => 'text',
            'backend' => 'Magento\Eav\Model\Entity\Attribute\Backend\ArrayBackend',
            'frontend' => '',
            'label' => 'My Attribute',
            'input' => 'multiselect',
            'class' => '',
    // instead values change your key as value and add your option like below with in `option_1`  array put key as store_id and label as value 
            'option' => ['value' => 
                            [
                             'option_1'=>[ 
                            //option_1 will be static it will add below labels in option_1 for **new**
                                  0=>'label for admin',    // here 0 is store id and 123 is value
                                  1=>'label for store1',
                                  13=>'label for store 13',
                                  14=>12121,
                                  15=>1212,
                                  16=>123
                                  ],
                            'option_2'=>[
                                  0=>'label for admin',
                                  1=>'label for store1',
                                  13=>'label for store 13',
                                  14=>32123,
                                  15=>123123123,
                                  16=>5152
                                  ],
                            ],
                           'order'=>//Here We can Set Sort Order For Each Value.
                                 [
                                      'option_1'=>1,
                                      'option_2'=>2
                                 ]
                        ], 
            'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE,
            'visible' => true,
            'required' => false,
            'user_defined' => true,
            'default' => '',
            'searchable' => false,
            'filterable' => false,
            'comparable' => false,
            'visible_on_front' => false,
            'used_in_product_listing' => true,
            'wysiwyg_enabled' => true,
            'unique' => false,
            'apply_to' => ''
        ]
    );
0

If i have a business and a personal store and want separate registration and drop down selection would i use this same method? also instead of

'option_1'=>1,'option_2'=>2

can i illustrate as

option_personal'=>personal 'option_business'=>Business?

and how would i point (depending on registration) to the correct store front end?

Thank you @MurtuzaZabuawala

  • Here in option_2 2 denotes 2nd option there would be no option_personal kind of thing were present – Murtuza Zabuawala Feb 5 at 6:29

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.