在我的magento sales_flat_quote表中,我添加了一个名为'simple_test_token'的新列(使用ALTER TABLE)。
现在,我正在尝试获取并为选定的引用对象设置该列的值。我正在尝试这个代码,它似乎没有得到或设置值。
// Get the quote
$quote = Mage::getModel('sales/quote')->load($quoteId);
// set quote value
$quote->setAttribute(1,'simple_test_token');
// Retrieve quote value
$tokenValue = $quote->getAttribute('simple_test_token');
编辑:
使用驼峰式getter和setter解决了这个问题。请注意,必须使用loadByIdWithoutStore()而不是load()来检索正确的引用对象。
//Set attribute
$quote = Mage::getModel('sales/quote')->loadByIdWithoutStore($quoteId);
$quote->setSimpleTestToken(1);
$quote->save()
//Get attribute
$quote->getSimpleTestToken();
答案 0 :(得分:1)
// Get the quote
$quote = Mage::getModel('sales/quote')->load($quoteId);
// set quote value
$quote->setSimpleTestToken(1);
$quote->save()
//保存后您可以检索值
//检索报价值
$tokenValue = $quote->getAttribute('simple_test_token');
如果您有任何疑问,请告诉我