Search code examples
attributesmagento2custom-attributes

Custom Attribute missing in the Flat table


Magento (2.2.4) is not adding my custom attribute with custom source to the flat table. The attribute is not available on the product list page (category). On the product detail page it is being displayed.

$catalogEavSetup->addAttribute(Mage_Catalog_Model_Product::ENTITY, 
'energy_label', array(
    'label' => 'Energielabel',
    'type' => 'int',
    'input' => 'select',
    'used_in_product_listing' => true,
    'visible_on_front' => true, 
    'source' => 'Company\CustomCatalog\Source\EnergyLabel',
    'apply_to' => null,
    'filterable' => false,
    'attribute_model' => null,
    'backend' => null,
    'table' => null,
    'frontend' => null,
    'frontend_class' => null,
    'required' => 0,
    'user_defined' => 1,
    'default' => '',
    'unique' => 0,
    'note' => null,
    'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_GLOBAL,

));

'visible_on_front' and 'used_in_product_listing' are both set to true. Reindexing did not help.

Any suggestions?


Solution

  • Your custom source model must also implement the following functions:

    getFlatColumns(), getFlatIndexes(), getFlatUpdateSelect($store)

    If you implement them, than your attribute should be added to the flat table after

    php bin/magento indexer:reindex