2013-01-08 29 views
0

我在表sales_flat_quote_item中創建了一個名爲'wiid'的新列。當任何產品形式願望清單添加到購物車時,我想將數據保存在此字段中。所以,這裏是我的MageWishlist_Model_Item:向sales_flat_quote_item添加新字段並保存數據

$quote_item = Mage::getModel('sales/quote_item')->load($cart->getQuote()->getItemByProduct($product)->getId()); 
//I log() this $quote_item and is returning the correct object 
$quote_item_id = $quote_item->getId(); 
//Is returning the correct quote item id from database 
$wishlist_item_id = $this->getId(); 
//Is returnig the correct wishlist item id 
$quote_item->setWiid($wishlist_item_id); 
$quote_item->save(); 

問題在於上面的最後兩行。它不是保存在數據庫中。

+1

什麼是你的問題? – cheesemacfly

+0

我假設在創建這個列之後,您完成了一次完整的緩存刷新。 Magento緩存表格的結構,如果你沒有清除緩存,它不會看到字段「wiid」。 – Ian

+1

嘗試刪除'var/cache'中的所有內容 有關表列的信息從'Zend_Db'緩存。正常的情況是,'Zend_Db'不知道保存數據。如果數據已設置且列存在,則會保存。正如伊恩所說 –

回答

0

每次在數據庫中添加新字段時,都必須在後端刷新「緩存存儲」。

0

你必須這樣做。

照片直接使用SQL語句:

$write = Mage::getSingleton('core/resource')->getConnection('core_write'); 
$query = "UPDATE sales_flat_quote_item SET your_field_here = '" . $yourContent . "' where item_id = ". $itemId; 
$write->query($query); 

或代替獲得quote_item你必須得到報價模型和迭代模型通過類似下面的項目:

$quote = Mage::getModel('sales/quote')->load($quoteId); 
$items = $quote->getAllItems(); 
foreach ($items as $item){ 
    $item->setWild("your_content_here"); 
    $item->save(); 
} 
相關問題