1

I have looked for answers to this issue and found this one. Unfortunately it is incomplete as in the "Manage Customers" table the date is still swapped. The solution provided in that answer fixes only the datetime visible when looking at a single separate customer profile.

Here is an example of the problem:

enter image description here

enter image description here

As far as I see while debugging - Magento records correctly the timestamp before the customer clicks the confirmation link. But after he clicks it the date gets swapped.

Can someone please provide a solution which fixes also the date in the "Manage customers" table?

george
  • 425
  • 4
  • 22

2 Answers2

2

Trying to debug this now and came up with the following:

1. Customer account creation without confirmation:

  • stores the dates in the correct format.

2. Customer account creation with required confirmation:

  • store the dates in the correct format.
  • when the customer clicks on the confirmation link, the created_date month and day values are swapped.

Quick fix:

In the admin, select customer to edit, don't edit anything, just click on the save button. Its not optimal but it works.

Module fix:

  1. Create a simple module
  2. add the following to config.xml in the global scope:

    <events>
        <customer_save_before>
            <observers>
                <customer_created_at_fix>
                    <model>modulename/observer</model>
                    <method>fixCreatedAt</method>
                </customer_created_at_fix>
            </observers>
        </customer_save_before>
    </events>
    
  3. Then create your observer: (Namespace/Modulename/Model/Observer.php)

    <?php
    class Namespace_Modulename_Model_Observer extends Mage_Core_Model_Abstract
    {
        /**
         * Fix created_at date
         *
         * @param Varien_Object $observer
         */
        public function fixCreatedAt($observer)
        {
            $customer = $observer->getEvent()->getCustomer();
    
            if (($customer instanceof Mage_Customer_Model_Customer)) {
                $ts = $customer->getCreatedAtTimestamp();
                $customer->setCreatedAt($ts);
            }
        }
    }
    

Clear cache and test :)

Edit:

(NB: The 'quick fix' will not work if the 'module fix' is implemented, since it fixes the dates already)

If the "last logged in date" shows a badly formatted year to somewhere in the future, then the easiest way to fix it is via the template, instead of adding rewrites to the core, etc.

Heres how to do it:

  1. Create a layout app/design/adminhtml/default/default/layout/local.xml and add

    <?xml version="1.0"?>
    <layout>
        <adminhtml_customer_edit>
            <reference name="customer_edit_tab_view">
                <action method="setTemplate"><template>solution/customer/tab/view.phtml</template></action>
            </reference>
        </adminhtml_customer_edit>
    </layout>
    
  2. Create a template app/design/adminhtml/default/default/template/solution/customer/tab/view.phtml and add

        <?php
        $lastLoginDateStore = $this->getStoreLastLoginDate();
        $createDateAdmin    = $this->getCreateDate();
        $createDateStore    = $this->getStoreCreateDate();
        ?>
        <div class="entry-edit">
            <div class="entry-edit-head"><h4 class="icon-head head-customer-view"><?php echo Mage::helper('customer')->__('Personal Information') ?></h4></div>
            <fieldset>
                <table cellspacing="2" class="box-left">
                    <tr>
                        <td><strong><?php echo $this->__('Last Logged In (%s):', $this->getStoreLastLoginDateTimezone()) ?></strong></td>
                        <td><?php echo $lastLoginDateStore ?> (<?php echo $this->getCurrentStatus() ?>)</td>
                    </tr>
                    <tr>
                        <td><strong><?php echo $this->__('Confirmed email:') ?></strong></td>
                        <td><?php echo $this->getIsConfirmedStatus() ?></td>
                    </tr>
                    <tr>
                        <td><strong><?php echo $this->__('Account Created on:') ?></strong></td>
                        <td><?php echo $createDateAdmin ?></td>
                    </tr>
                    <?php if ($createDateAdmin != $createDateStore): ?>
                    <tr>
                        <td><strong><?php echo $this->__('Account Created on (%s):', $this->getStoreCreateDateTimezone()) ?></strong></td>
                        <td><?php echo $createDateStore ?></td>
                    </tr>
                    <?php endif; ?>
                    <tr>
                        <td><strong><?php echo $this->__('Account Created in:') ?></strong></td>
                        <td><?php echo $this->getCreatedInStore() ?></td>
                    </tr>
                    <tr>
                        <td><strong><?php echo $this->__('Customer Group:') ?></strong></td>
                        <td><?php echo $this->getGroupName() ?></td>
                    </tr>
                </table>
                <address class="box-right">
                    <strong><?php echo $this->__('Default Billing Address') ?></strong><br/>
                    <?php echo $this->getBillingAddressHtml() ?>
                </address>
            </fieldset>
        </div>
        <?php echo $this->getChildHtml('', true, true); ?>
    

Clear cache and give it a test.

Shaughn
  • 1,762
  • 13
  • 21
  • The quick fix works - thanks!

    As for the other one - I am trying to implement it inside another simple module (namespace=George, modulename=Solution). But when adding your xml code in the tag and setting <model>solution/observer</model> then upon registering of new customer I get this error: http://pastebin.com/kbMSXtPk

    How to fix that?

    – george May 11 '15 at 14:30
  • Also - if I use your module-fix do I still need to run in parallel this fix (which is partial as I explained in the question): http://magento.stackexchange.com/questions/18062/customer-created-at-date-off-by-months/31225 – george May 11 '15 at 14:33
  • Correction on the fist comment: I use <model>george_solution/observer</model> but it still doesn't work. – george May 11 '15 at 14:38
  • 1
    @george - nope no need for that other fix, the module fix should handle it just fine. Can you pastebin you config.xml please so i can take a look. Seems like Magento cant fine your observer. – Shaughn May 11 '15 at 15:49
  • here it is: http://pastebin.com/p8wKdcGu - note: I still haven't removed the other fix from it but I guess that shouldn't matter for the error. – george May 11 '15 at 19:50
  • 1
    ah ok, u dont have you model defined. add to the models: <solution><class>George_Solution_Model</class></solution> then change your observer to <model>solution/observer</model>. Also make sure that observer resides in the following directory: George/Solution/Model/Observer.php – Shaughn May 11 '15 at 20:37
  • Thanks! It seems this works. Can you please check if this is what it should be: http://pastebin.com/NxpKZY0n – george May 11 '15 at 20:57
  • 1
    Yip, that looks good – Shaughn May 11 '15 at 21:02
  • Thanks, I will mark the answer :) But there is another strange thing now. When the customer is logged in I see "Last Logged In: May 11, 8131 4:31:37 PM (Online)". Can you fix that too so the solution is really complete? – george May 11 '15 at 21:04
  • 1
    I will need to run another test and replicate. Ill post here as soon as i have solution – Shaughn May 11 '15 at 22:44
  • BTW the quick fix doesn't seem work after the module fix is implemented. I wonder if there is a way to fix existing customers with wrong date? – george May 11 '15 at 23:21
  • did you have a chance to test further? – george May 14 '15 at 07:56
  • 1
    Sorry, urgent work to do. I will update the answer in a bit. – Shaughn May 14 '15 at 12:29
  • 1
    Ok edit is up, you should be good to make the changes and test :) – Shaughn May 14 '15 at 12:51
  • Thanks @Shaughn. Just to ask (before implementing the edit) - I actually disabled the "module fix" and still the quick fix didn't work. Is there any way to fix the old accounts? Or will the latest edit do it? – george May 14 '15 at 15:06
  • oh damn, forgot about the old accounts as well – Shaughn May 14 '15 at 15:37
  • I have added the template and it seems to work for the year. It doesn't fix older account registration dates (still flipped). Too bad it is already 14th and I can't test :) Please let me know if you find a fix for existing accounts with wrong date. – george May 14 '15 at 19:52
  • Can you screenshot an old account as i have tried both fixes and they seem to resolve the issue. – Shaughn May 14 '15 at 21:24
  • These two customers registered on 9 and 10.May: https://goo.gl/qp5oMz – george May 15 '15 at 07:51
  • did you find a solution for existing accounts? – george Jun 02 '15 at 21:32
0

I have also faced the same issue for quite a long time till I found the solution.

Summary of the files in the Magento Extension for solving the Magento Date Switch Fix:

app/code/local/CustomerParadigm/Datefix/Model/Entity/Attribute/Backend/Time/Created.php:

<?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@magento.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.magento.com for more information.
 *
 * @category    Mage
 * @package     Mage_Eav
 * @copyright  Copyright (c) 2006-2015 X.commerce, Inc. (http://www.magento.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 CustomerParadigm_Datefix_Model_Entity_Attribute_Backend_Time_Created extends Mage_Eav_Model_Entity_Attribute_Backend_Time_Created
{

    /**
     * Returns date format if it matches a certain mask.
     * @param $date
     * @return null|string
     */
/* This shouldn't be needed for the datetime switch bug fix. Removing for testing.
    protected function _getFormat($date)
    {
        if (is_string($date) && preg_match('#^\d{4,4}-\d{2,2}-\d{2,2} \d{2,2}:\d{2,2}:\d{2,2}$#', $date)) {
            return 'yyyy-MM-dd HH:mm:ss';
        }
        return null;
    }
*/

    /**
     * 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 {
        // Date switch fix
            $date = strtotime($date);

            // convert to UTC
            $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);

    // Date switch fix
    if (!is_null($date)) {
        $date = strtotime($date);
    }

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

        parent::afterLoad($object);

        return $this;
    }
}

app/code/local/CustomerParadigm/Datefix/etc/config.xml:

<config>
    <global>
        <models>
            <eav>
                <rewrite>
                    <entity_attribute_backend_time_created>CustomerParadigm_Datefix_Model_Entity_Attribute_Backend_Time_Created</entity_attribute_backend_time_created>
                </rewrite>
            </eav>
        </models>
    </global>
</config>

app/etc/module/ CustomerParadigm_Datefix.xml:

<?xml version=”1.0″?>
<config>
    <modules>
        <CustomerParadigm_Datefix>
            <active>true</active>
            <codePool>local</codePool>
        </CustomerParadigm_Datefix>
    </modules>
</config>
Siarhey Uchukhlebau
  • 15,957
  • 11
  • 54
  • 83