Webkul
Services
Technologies Bagisto QloApps
iOS Android SAP BigCommerce Wix
Trusted by
Samsung Intel Toyota Walmart Disney Nokia Nestlé Decathlon
See all customers
Back to Top
DEV

Custom product attributes with Source model not getting added to Flat table in Magento 2

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 👨‍💻

. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


Be the first to comment.

Back to Top

Message Sent!

If you have more details or questions, you can reply to the received confirmation email.

Back to Home