Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/magento/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
销售订单表中的更新-Magento型号_Magento - Fatal编程技术网

销售订单表中的更新-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

我想更新我正在使用的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 $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付款

谢谢您的帮助,我会尝试一下,并让您知道:)