Add a column to quote item table
-
16-10-2019 - |
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();
Solution
In order to add column to sales_flat_quote_item
you will have to write an upgrade script for that follow below steps.
- Create a module or use your existing custom module.
Modify your
config.xml
to add a setup resource with classMage_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>
Create a directory
data/your_module_setup
in your moduleCreate a
data-install
ordata-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();
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange