Magento 新增字段的值读写丢失原因

某实体新增字段handreturn_status,欲操作之:

$order_info = Mage::getModel('sales/order')->load($order_id);
//setData will faile
$order_info->setData('handreturn_status', 2);  // old value 0
$order_info->save();
echo  $order_info->getData('handreturn_status');  //output 0 

//setxxx will success
$order_info->setHandreturnStatus(2);
$order_info->save();
echo $order_info->getHandreturnStatus();  //output 2


原因是load方法只部分加载了实体的字段(由magento内核预先定义好的),而getData和setData方法只会操作此部分字段,
其他额外的字段,要靠setxxx和getxxx来操作。




原文地址:https://www.cnblogs.com/caryfang/p/5112694.html