销售订单表中的更新-Magento型号
我想更新我正在使用的magento中的一个字段值销售订单表中的更新-Magento型号,magento,Magento,我想更新我正在使用的magento中的一个字段值 $data = array('xxx'=>$xxx); $orderModel = Mage::getModel('sales/order')->load($orderId)->addData($data); try { $orderModel->setId($orderId)->save(); echo "Data updated successfully."; } catch (Exception
$data = array('xxx'=>$xxx);
$orderModel = Mage::getModel('sales/order')->load($orderId)->addData($data);
try {
$orderModel->setId($orderId)->save();
echo "Data updated successfully.";
} catch (Exception $e){
echo $e->getMessage();
}
但它不起作用,任何人都可以建议我在更新数据时如何创建问题。您的代码setId($orderId)
看起来您要么想明确设置订单entity\u id
(即创建订单),要么您不知道不需要setId($orderId)的事实
加载后,如果您只想更新给定的订单
如果您试图创建订单:sales/order
模型通常不允许明确设置订单的实体id
,因为它使用默认情况下自动递增的主键
如果您试图更新现有订单:从save()
链中删除setId($orderId)
其次,如果希望能够将其值保存到数据库中,则首先需要使用xxx
属性扩展sales/order
模型
有几种方法可以扩展销售/订单
模型,使其具有自定义属性。例如,您可以在app/code/local/Mycompany/Mymodule/sql/myresource/
文件夹中拥有自己的安装脚本:
// Mage_Eav_Model_Entity_Setup
$oInstaller = $this;
// Add EAV attribute
$oInstaller->startSetup();
$oInstaller->addAttribute(
'order',
'my_attribute',
array(
'type' => 'int'
)
);
$oInstaller->endSetup();
// Add flat attribute
if (Mage::getVersion() >= 1.1) {
$oInstaller->startSetup();
$oConnection = $oInstaller->getConnection();
$oConnection->addColumn(
$oInstaller->getTable('sales_flat_order'),
'my_attribute',
'TINYINT(1) NOT NULL'
);
$oInstaller->endSetup();
}
您可以执行MAGIC功能、
get
和set
功能
直接尝试:
// if your attribute is column named is_active then you can getIsActive() or setIsActive(1)
$orderModel = Mage::getModel('sales/order')->load($orderId)->setYourAttribute($data);
// it means you can set and get column named by ['your_attribute']
try {
$orderModel->setId($orderId)->save();
echo "Data updated successfully.";
} catch (Exception $e){
echo $e->getMessage();
}
嗯,我不知道你为什么要设置销售/订单模型的实体id。但是它不起作用,因为实体id可以是另一个表上的外键,例如:
销售\u平面\u订单\u付款
谢谢您的帮助,我会尝试一下,并让您知道:)