3

Is there any way to add product attribute with different store labels through Magento2 setup script?

If we pass 'label' it only assign default label of the attribute. I tried with frontend_label but that didn't worked.

$options =             [
        'type' => $type,
        'backend' => $input == 'multiselect'? 'Magento\Eav\Model\Entity\Attribute\Backend\ArrayBackend' : '',
        'frontend' => '',
        'label' => $attributeLabel,
        'frontend_label' =>  array(0=>$attributeLabel,1=>$attributeLabel.' test1',2=>"",3=>"",4=>"",5=>$attributeLabel.' test5',6=>"",7=>"",8=>""),
        'input' => $input,
        'class' => '',
        'source' => in_array($input, ['text', 'textarea', 'multiselect'])
            ? '' :'Magento\Eav\Model\Entity\Attribute\Source\Table',
        'global' => $is_Global ? \Magento\Catalog\Model\ResourceModel\Eav\Attribute::SCOPE_GLOBAL : \Magento\Catalog\Model\ResourceModel\Eav\Attribute::SCOPE_STORE,
        'visible' => true,
        'required' => false,
        'user_defined' => true,
        'searchable' => true,
        'filterable' => $isFilter,
        'comparable' => true,
        'visible_on_front' => $showOnProductPage,
        'used_in_product_listing' => $usedInProductListing,
        'unique' => false,
        'group' => $group,
        'apply_to' => '',
        'wysiwyg_enabled' => $wysiwyg,
    ];



    $eavSetup->addAttribute(
        \Magento\Catalog\Model\Product::ENTITY,
        $attributeCode,
        $options
    );

1 Answer 1

0

Use the following code to get the labels of custom attributes store wise :

$attribute = $this->_objectManager->create('Magento\Catalog\Model\ResourceModel\Eav\Attribute')->load($id);

$labelStoreWise = $attribute->getStoreLabel();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.