There's a time issue I've noticed with saving new customers and the created_at attribute, where if you save the model twice, the time stored will be incorrect. To get around the issue you can call load() directly after the first save.
For example, you set the customer data, and then call save(). Created_at gets set with Mage_Eav_Model_Entity_Attribute_Backend_Time_Created::beforeSave() which uses Varien_Date::now(), which generates a date time stamp in UTC.
public function beforeSave($object)
{
$attributeCode = $this->getAttribute()->getAttributeCode();
$date = $object->getData($attributeCode);
if (is_null($date)) {
if ($object->isObjectNew()) {
$object->setData($attributeCode, Varien_Date::now());
}
} else {
// convert to UTC
$zendDate = Mage::app()->getLocale()->utcDate(null, $date, true, $this->_getFormat($date));
$object->setData($attributeCode, $zendDate->getIso());
}
return $this;
}
Customer_entity.created_at is mysql type timestamp, not datetime, so when this gets saved, it also stores the timezone. After the first save, the time in memory is in UTC, and the column is in UTC (+0000).
After the second save, beforeSave() gets called again. However, the object is not considered new anymore and it assumes the time in memory is stored in the store local time, as that's what afterLoad() does. The time gets incorrectly converted from store local time to UTC time before saving, when the time in memory is actually still in UTC, so the time stored has actually twice the intended offset.
So I'm curious, is this a Magento bug? Or is it considered standard practice that after the first time you save a model, that that is considered the end of life for that object? That would not make sense, because of course people may want to create after_save observers for that object and perform additional tasks with it. Would love to hear anyone's input.