1

I added new field in catalog_product_flat_1 table. By using below code:

$installer = $this;  
$installer->startSetup();
 if (!$installer->getConnection()->tableColumnExists($installer->getTable('catalog_product_flat_1'), 'most_clicked')) 
    {
       $installer->getConnection()->addColumn($installer->getTable('catalog_product_flat_1'), 'most_clicked', "INT( 25 ) int(25) default (0)");
    }  

$installer->endSetup();

This code works fine in localhost. In live site new field got added to table but after indexing or flushing cache, new field got disappeared.

Is this not the right way to add new field in table?

What is the correct way to add new field in catalog_product_flat_1 table and sales_flat_order_item table?

Is above code is only applicable to sales_flat_quote_item table?

3

The flat tables for products and categories are dynamic. They are generated on the fly when you reindex based on several criterias.

For the products it's based on whether or not the product attribute is allowed in product listing I think.

Thus, if you want to add a new column to this table you need to add a new product attribute and ensure "Used in product listing" is set to Yes.

You can refer to this question if you want to add a new product attribute programmatically: Magento add custom attribute programmatically in a specific fieldset

  • thanks for your answer. One more question ie. How to create attribute in sales flat table through backend in magento? – jassi Nov 1 '16 at 9:00
  • @jassi you cant do it from the backend for sales flat tables you can use the script you posted in your question to do so ;) – Raphael at Digital Pianism Nov 1 '16 at 9:11
  • 1
    thanks for the information and I would also like to congratulate for being top in helping others :) – jassi Nov 1 '16 at 9:15
  • @jassi no problem thank you have a nice day – Raphael at Digital Pianism Nov 1 '16 at 9:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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