5

This question already has an answer here:

I just installed a fresh copy of magento 1.8.1 (was having this same problem on my production site) and every time a user edits their account the "created_at" value is updated in the database. And it appears it's being updated without any consistency. I get "created_at" date values for times in the future and past.

Does anyone know a solution to this?

Edit: Actually my original question isn't really the main problem anymore. The problem is that the created_at time is wrong. I do not get the issue of it changing on save anymore (odd).

How to duplicate the issue: 1. Install a fresh copy of 1.8.1 2. Register a new customer on the frontend 3. Check the "Customer Since" date in the admin panel under manage customers.

marked as duplicate by philwinkle, Keyul Shah, Marius, Fabian Blechschmidt, user487772 Mar 5 '14 at 20:51

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • @philwinkle I've read that .. I altered the table a bit and I dont seem to be getting the change on save, but now the created_at time is off but about 2 months in advance. If i manually insert a customer into the DB then the time stamp is right or if i enter a customer in the database by using the Mage::getModel('customer/customer) model, the time stamp is correct. Confused!!? :/ – Alex Lacayo Mar 5 '14 at 2:35
  • Oh yea, but the "updated_at" field is always correct... ?? – Alex Lacayo Mar 5 '14 at 2:36
3

Found the issue. It was also causing the customer created_at date to be way off in the customer_entity table, which is why in admin > customers > manage customers the "Customer Since" column on the grid was way off.

app/code/core/Mage/Eav/Model/Entity/Attribute/Backend/Time/Created.php

Compared the files from 1.8.0 and 1.8.1 and there were some changes in 1.8.1. I commented out a few lines that were causing the problem. Not sure if it's the best solution as I have basically converted it to the same as 1.8.0

<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/osl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @category    Mage
 * @package     Mage_Eav
 * @copyright   Copyright (c) 2013 Magento Inc. (http://www.magentocommerce.com)
 * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */

/**
 * Entity/Attribute/Model - attribute backend default
 *
 * @category   Mage
 * @package    Mage_Eav
 * @author      Magento Core Team <core@magentocommerce.com>
 */
class Mage_Eav_Model_Entity_Attribute_Backend_Time_Created extends Mage_Eav_Model_Entity_Attribute_Backend_Abstract
{
    /**
     * Set created date
     * Set created date in UTC time zone
     *
     * @param Mage_Core_Model_Object $object
     * @return Mage_Eav_Model_Entity_Attribute_Backend_Time_Created
     */
    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

            //commented out by alex lacayo
            //$zendDate = Mage::app()->getLocale()->utcDate(null, $date, true);
            //$object->setData($attributeCode, $zendDate->getIso());
        }

        return $this;
    }

    /**
     * Convert create date from UTC to current store time zone
     *
     * @param Varien_Object $object
     * @return Mage_Eav_Model_Entity_Attribute_Backend_Time_Created
     */
    public function afterLoad($object)
    {   

        $attributeCode = $this->getAttribute()->getAttributeCode();
        $date = $object->getData($attributeCode);

        $zendDate = Mage::app()->getLocale()->storeDate(null, $date, true);
        $object->setData($attributeCode, $zendDate->getIso());

        parent::afterLoad($object);

        return $this;

    }
}
  • I'm pretty sure that it returns $this so that it can achieve a fluent interface. I would be more concerned with the parent event not firing as well. This seems like an awfully destructive means of handling. – philwinkle Mar 5 '14 at 19:51
  • @philwinkle Thanks. I changed it to return $this and it still works. It seems like the if & else were running on beforeSave($object) leading me to believe it was being triggered twice. By uncommenting out the lines i get random created_at times. Sometimes the date is 2 months in advance, sometimes 2 months in the past. This was all on a brand new copy of 1.8.1. Do you by any chance get this error as well? – Alex Lacayo Mar 5 '14 at 20:22
  • Actually the afterLoad has nothing to do with the problem. So that can be left alone. I am experiencing a problem in the else statement. The created_at time should be a one and done set. Its checking if its not set, then do something, if it is set, then change it. Why would they change it? – Alex Lacayo Mar 5 '14 at 20:28
  • What is your Magento install's locale? – philwinkle Mar 5 '14 at 20:38
  • 1
    is this still a duplicate? the database isn't set to update on save for created_at anymore (just did an upgrade form 1.5.1.0 to 1.8.1.0) but i'm seeing the same behavior as the OP. i tried his solution, but after implementing it, my dates were transposed. – Laura Apr 8 '14 at 20:07

Not the answer you're looking for? Browse other questions tagged or ask your own question.