- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-28-2016
12:50 AM
06-28-2016
12:50 AM
How to save in database from Model Order
I'm trying to keep values in the database by writing a comment from an order (from Administration panel ) .
I have an array with "key " = > "value" of all I want to save . I want to introduce these values within the " sales_flat_order 'table. I've done as follows:
$model = Mage::getModel("sales/order")->load($request->getParams()["order_id"]);
This to get the order.
I have tried these four ways, but it doesn't work. Why?
1:
$model->addData($data); try { $model->save(); } catch (Exception $e){ echo $e->getMessage(); }
2:
$model->setData($key, $value); try { $model->save(); } catch (Exception $e){ echo $e->getMessage(); }
3:
$write_connection = Mage::getSingleton('core/resource')->getConnection('core_write'); $query = "UPDATE {$table} SET {$sql} WHERE entity_id = '".$request->getParams()["order_id"]."'"; $writeConnection->query($query);
4:
$write_connection = Mage::getSingleton('core/resource')->getConnection('core_write'); $where = $write_connection->quoteInto('entity_id =?', $request->getParams()["order_id"]); $write_connection->update($table, $data, $where);
Thanks!!
Labels:
2 REPLIES 2
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2016
05:45 AM
07-05-2016
05:45 AM
Re: How to save in database from Model Order
Hello Sergio,
Replace 'addData' with setData as
model->setData($data); try { $model->save(); } catch (Exception $e){ echo $e->getMessage(); }
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2016
11:47 PM
07-14-2016
11:47 PM
Re: How to save in database from Model Order
Hi Sergio,
setData() function is only set one field value on one call. it can set multiple field value using multiple call of setData function
addData() function is set multiple field values using array with array key as field index.
$orderid=1; $orders = Mage::getModel('sales/order'); $orders->setData('column_name','value'); $orders->setId($orderid); $orders->save();