Magento - add field to sales_flat_quote

2019-08-28 19:12发布

问题:

I have created a module which requires an additional field to be added to the sales_flat_quote table / model.

Everything appears to work fine in my install script and the new field can be seen in the database.

When retrieving a quote object and storing a value against my new field the value never gets recorded to the database. The save method doesnt product an error or exception but the value never sticks.

If it makes a difference, I am trying to save the value to the quote from an observer, during the checkout process.

Here is the code I am using in my install script:

$setup = new Mage_Sales_Model_Mysql4_Setup('sales_setup');
$setup->getConnection()->addColumn(
        $setup->getTable('sales_flat_quote'),
        'test_attribute',
        'text NULL DEFAULT NULL'
    );

$setup->addAttribute('quote', 'test_attribute', array('type' => 'text', 'visible' => false));

Am I missing something obvious here?

回答1:

Don't know why you create this object $setup = new Mage_Sales_Model_Mysql4_Setup('sales_setup'); If you look for example into \app\code\core\Mage\Sales\sql\sales_setup\mysql4-upgrade-1.3.99-1.4.0.0.php, you will see:

/* @var $installer Mage_Sales_Model_Entity_Setup */
$installer = $this;
$installer->startSetup();

/* Include code from mysql4-upgrade-0.9.38-0.9.39.php */
$installer->getConnection()->addColumn($installer->getTable('sales_flat_quote_item'),
    'store_id', 'smallint(5) unsigned default null AFTER `product_id`');

And of course you should delete cache, change your module version in config.xml to number bigger than you have for you module in core_resource table.



标签: magento