Add a column to quote item table

The question:

I want to add a column to the sales_flat_quote_item (and ..._order_item) table through an install script, but when I go to the table sales_flat_quote_item (or ..._order_item) in my database – the column is not there.

The install script’s version is 0.0.1. My config.xml is also 0.0.1.

I have cleared the cache. I refreshed the back-end, so the script has ran.

Any clues?

$installer = $this;
$installer->startSetup();
$installer->getConnection()->addColumn($installer->getTable('sales/quote_item'), 'print_sku', "varchar NOT NULL");
$installer->getConnection()->addColumn($installer->getTable('sales/order_item'), 'print_sku', "varchar NOT NULL");
$installer->endSetup();

The Solutions:

Below are the methods you can try. The first solution is probably the best. Try others if the first one doesn’t work. Senior developers aren’t just copying/pasting – they read the methods carefully & apply them wisely to each case.

Method 1

In order to add column to sales_flat_quote_item you will have to write an upgrade script for that follow below steps.

  1. Create a module or use your existing custom module.
  2. Modify your config.xml to add a setup resource with class Mage_Sales_Model_Resource_Setup:

    <global>
        <resources>
            <your_module_setup>
                <setup>
                    <module>Your_Module</module>
                    <class>Mage_Sales_Model_Resource_Setup</class>
                </setup>
           </your_module_setup>
         </resources>
     </global>
    
  3. Create a directory data/your_module_setup in your module

  4. Create a data-install or data-upgrade script containing the following code:

    $installer = $this;
    
    $installer->startSetup();
    
    $installer->addAttribute(
        'quote_item',  /* order, quote, order_item, quote_item */
        'your_attribute_code', 
        array(
            'type' => 'varchar', /* int, varchar, text, decimal, datetime */
            'nullable' => false, /* default true */
            'grid' => false, /* or true if you wan't use this attribute on orders grid page */
        )
    );
    
    $installer->endSetup();
    


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Comment