magento将数据存储在自定义列中
我在sales_flat_quote_项目中添加了两个文本列,以存储数据,并在将产品添加到购物车时出于其他原因。我的问题是我不能保存数据。我尝试了很多例子,但都没有成功。 在这里,我添加了coulmns:magento将数据存储在自定义列中,magento,Magento,我在sales_flat_quote_项目中添加了两个文本列,以存储数据,并在将产品添加到购物车时出于其他原因。我的问题是我不能保存数据。我尝试了很多例子,但都没有成功。 在这里,我添加了coulmns: $installer = $this; $connection = $installer->getConnection(); $installer->startSetup(); $installer->getConnection() ->addColumn($i
$installer = $this;
$connection = $installer->getConnection();
$installer->startSetup();
$installer->getConnection()
->addColumn($installer->getTable('sales/quote_item'),
'pack_name',
array(
'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
'nullable' => true,
'default' => null,
'comment' => 'pack_name'
)
);
$installer->endSetup()
)
这是我在observer中尝试保存数据的代码:
$quote_item = Mage::getModel('sales/quote_item')->load($quote->Id);
$quote_item->setPackName($string);
$quote_item->save();
有什么帮助吗?不建议像这样向平面表中添加列。这些神奇的方法不起作用,因为您对模式的更新违背了Magento的最佳实践。但是,如果您只想快速修复,可以使用原始SQL查询:
<?php
$transaction = Mage::getSingleton('core/resource')->getConnection('core_write');
try {
$transaction->beginTransaction();
$query_string = "UPDATE sales_flat_quote_item
SET pack_name='packname'
WHERE id='id'";
$transaction->query($query_string);
$transaction->commit();
}
catch (Exception $e) {
$transaction->rollBack();
}
不过要小心,它不安全。确保数据已清理。为什么不建议添加这样的列?我该怎么办?我不是在寻找一个快速的解决方案,我想要正确的方法。