获取/设置magento表中的自定义列


Getting / Setting a custom column in magento table

在我的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();
//      Get the quote
        $quote = Mage::getModel('sales/quote')->load($quoteId);
//      set quote value
        $quote->setSimpleTestToken(1);
        $quote->save()

//保存后可以检索值

//检索报价

 $tokenValue = $quote->getAttribute('simple_test_token');

如果您有任何疑问请告诉我