Let’s suppose you created a drop-down type custom product attribute that has a source model as in Create drop down product attribute in Magento 2 blog.
Even when we set used_in_product_listing=1 the attribute “attribute_code” will not be added to the flat table because we are using a source model for this attribute.
So to add this attribute to the flat table (catalog_product_flat_<store_id>) we need to implement a method in Company\Module\Model\Config\Source\Options class as shown below,
public function getFlatColumns() { return ['attribute_code'=>['type'=>'integer', 'length'=>2]]; }
Thank you for reading the blog. Please let me know by commenting if you face any issues.
Happy Coding 👨💻
Be the first to comment.