6

I Have Created custom attribute for configurable products. It is Showing in Add configurable Product section. enter image description here

But I Can't get those attributes in below section.

enter image description here

$eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);
    $eavSetup->addAttribute(
        \Magento\Catalog\Model\Product::ENTITY,
        'paper_size',
        [
            'group' => 'Pricing Calculator',
            'type' => 'varchar',
            'backend' => '',
            'frontend' => '',
            'sort_order' => 10,
            'label' => 'Card Size',
            'input' => 'select',
            'class' => '',
            'source' => 'Lts\MultipleDropdown\Model\Config\Source\Optionssize',
            'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_GLOBAL,
            'visible' => true,
            'required' => false,
            'user_defined' => false,
            'default' => '',
            'searchable' => true,
            'filterable' => true,
            'comparable' => false,
            'visible_on_front' => true,
            'used_in_product_listing' => true,
            'unique' => false,
            'apply_to'=>'configurable'
        ]
    );
9
  • Show your custom attribute code
    – Priyank
    Apr 3, 2017 at 8:41
  • Have you set this attribute in attribute set? Apr 3, 2017 at 9:07
  • custom attribute code added. Apr 3, 2017 at 9:07
  • Custom Attributes are set in Default Attribute Set. Apr 3, 2017 at 9:11
  • are you created product is contains default attribute set? Apr 3, 2017 at 9:14

7 Answers 7

2

1- Please check that Attribute you have created is assigned to the attribute set.

2- Please run the reindex command

php bin/magento indexer:reindex

3- flush the cache

php bin/magento cache:flush
2

Make sure to add the custom attribute to the 'Attribute Set' the configurable product is using.

You can have different configurable products using different attribute sets. Check the attribute set used for your configurable product here:

  • Catalog -> Product -> [Edit] -> General -> Attribute Set

Add the custom attribute to the attribute set used by your configurable product here:

  • Store - Attribute Set -> [Edit] -> drag unsigned attributes to the attribute set
2

this is the good code to create a product attribute that can be used for configurable product for Magento 2.3.

The required parameters are :

'source'=> \Magento\Eav\Model\Entity\Attribute\Source\Table::class
'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_GLOBAL,
'user_defined' => true,
'visible' => true,

complete code

$eavSetup->addAttribute(
        \Magento\Catalog\Model\Product::ENTITY,
        'size',
        [
            'group' => 'Erp',
            'type' => 'int',
            'label' => 'Taille',
            'input' => 'select',
            'required' => false,
            'sort_order' => 20,
            'position'=> 0,
            'source'=> \Magento\Eav\Model\Entity\Attribute\Source\Table::class,
            'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_GLOBAL,
            'user_defined' => true,
            'is_used_in_grid' => true,
            'is_visible_in_grid' => true,
            'is_filterable_in_grid' => true,
            'visible' => true,
            'is_html_allowed_on_front' => false,
            'visible_on_front' => false
        ]
    );
1

See how the attribute grid collection is created in

\Magento\ConfigurableProduct\Ui\DataProvider\Attributes::getData

then \Magento\ConfigurableProduct\Model\ConfigurableAttributeHandler::getApplicableAttributes

return $collection->addFieldToFilter(
        'frontend_input',
        'select'
    )->addFieldToFilter(
        'is_user_defined',
        1
    )->addFieldToFilter(
        'is_global',
        \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_GLOBAL
    );

You should set is_user_defined to true. (test on Magento 2.2)

1

This will surely work:

public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
    {

        $eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);

        $eavSetup->addAttribute(
            \Magento\Catalog\Model\Product::ENTITY,
            'paper_size',
            [
                'type' => 'int',
                'backend' => '',
                'frontend' => '',
                'label' => 'Size',
                'input' => 'select',
                'class' => '',
                'source' => '',
                'global' => \Magento\Catalog\Model\ResourceModel\Eav\Attribute::SCOPE_GLOBAL,
                'visible' => true,
                'required' => false,
                'user_defined' => true,
                'default' => 0,
                'searchable' => true,
                'filterable' => true,
                'comparable' => true,
                'visible_on_front' => true,
                'used_in_product_listing' => true,
                'unique' => false,
                'apply_to' => implode(',', [Type::TYPE_SIMPLE, Type::TYPE_VIRTUAL, Configurable::TYPE_CODE]),
                'is_used_in_grid' => true,
                'is_visible_in_grid' => true,
                'is_filterable_in_grid' => true,
                'visible_in_advanced_search' => true
            ]
        );

    }
0

Your custom attribute must have global scope to be used for configurable products, see Magento 2: new attribute not showing in list configurable product

0

In my case module was disabled Xd.

Check module Status: bin/magento module:status

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.