5

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.

Alex Lacayo
  • 330
  • 4
  • 11
  • @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 05 '14 at 02:35
  • Oh yea, but the "updated_at" field is always correct... ?? – Alex Lacayo Mar 05 '14 at 02:36

1 Answers1

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;

    }
}
Alex Lacayo
  • 330
  • 4
  • 11
  • 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 05 '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 05 '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 05 '14 at 20:28
  • What is your Magento install's locale? – philwinkle Mar 05 '14 at 20:38
  • English / United States. Set to American/Chicago CT time. I even double checked my server time and mysql time. Everything is good. I duplicated this error 3 times. 1) Upgrading my production from 1.7 to 1.8.1. 2) Installing a brand new copy of 1.8.1 on test server. 3) installing a brand new copy of 1.8.0 (worked perfectly here) & then upgrading to 1.8.1 (failed again) – Alex Lacayo Mar 05 '14 at 20:44
  • 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 08 '14 at 20:07
  • @AlexLacayo, I have seen similar problems with "random" created_at times. It's not actually random, though, if you're seeing the same thing I was. It's swapping the month and day. So if you have a customer created on January 4th, when it re-saves it will now say April 1st. Save again, and it toggles back. I have a question on SO about the same issue: http://stackoverflow.com/questions/29418501/magento-locale-timezone-issue. – Mageician Apr 15 '15 at 19:34
  • I think it changes it in the beforeSave because it modifies it in the afterLoad. If it was saved in database as UTC, changed to BST in the afterLoad, and then saved without converting back to UTC, it would break. – Matthew Haworth Sep 30 '15 at 09:06
  • I am using Version 1.9.1 and facing same issue - date and month swap. Also time is showing incorrect. Our locale is Indian standard time(Asia/calcatta).

    I have updated created.php - any one found solution to this.

    – Bijal Bhavsar Jan 22 '16 at 12:05