4

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();

1 Answer 1

8

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();
    
1
  • I used my code for the script, but you gave me the idea to add the code in my config.xml. I didn't know I have to do that also. Thanks.
    – Syspect
    Jan 10, 2014 at 9:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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