Magento, set sales order, invoice, shipment, credit memo created_at after before_save
and before after_save
event.
Basically, all sales related object order, shipment, credit memo, invoice created_at
field value set whenever it prepareDataForSave()
Prepare data for save at database.
If you see that Magento sales object's resource Db Abstract class Mage_Sales_Model_Resource_Abstract
, then you can understand that.
We already now that prepareDataForSave() fire when after before_save
and before after_save
event. You can get a clear view at resource db abstract class Mage_Core_Model_Resource_Db_Abstract
at function save(),
public function save(Mage_Core_Model_Abstract $object)
{
.....
$this->_beforeSave($object);
$this->_checkUnique($object);
if (!is_null($object->getId()) && (!$this->_useIsObjectNew || !$object->isObjectNew())) {
$condition = $this->_getWriteAdapter()->quoteInto($this->getIdFieldName().'=?', $object->getId());
/**
* Not auto increment primary key support
*/
if ($this->_isPkAutoIncrement) {
$data = $this->_prepareDataForSave($object);
unset($data[$this->getIdFieldName()]);
$this->_getWriteAdapter()->update($this->getMainTable(), $data, $condition);
} else {
$select = $this->_getWriteAdapter()->select()
->from($this->getMainTable(), array($this->getIdFieldName()))
->where($condition);
if ($this->_getWriteAdapter()->fetchOne($select) !== false) {
$data = $this->_prepareDataForSave($object);
unset($data[$this->getIdFieldName()]);
if (!empty($data)) {
$this->_getWriteAdapter()->update($this->getMainTable(), $data, $condition);
}
} else {
$this->_getWriteAdapter()->insert($this->getMainTable(), $this->_prepareDataForSave($object));
}
}
} else {
$bind = $this->_prepareDataForSave($object);
if ($this->_isPkAutoIncrement) {
unset($bind[$this->getIdFieldName()]);
}
$this->_getWriteAdapter()->insert($this->getMainTable(), $bind);
$object->setId($this->_getWriteAdapter()->lastInsertId($this->getMainTable()));
if ($this->_useIsObjectNew) {
$object->isObjectNew(false);
}
}
......
$this->_afterSave($object);
return $this;
}