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?

2 Answers 2

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.

20
  • 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
    Commented May 11, 2015 at 15:49
  • 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
    Commented May 11, 2015 at 20:37
  • 1
    Yip, that looks good
    – Shaughn
    Commented May 11, 2015 at 21:02
  • 1
    I will need to run another test and replicate. Ill post here as soon as i have solution
    – Shaughn
    Commented May 11, 2015 at 22:44
  • 1
    Sorry, urgent work to do. I will update the answer in a bit.
    – Shaughn
    Commented May 14, 2015 at 12:29
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 [email protected] 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 <[email protected]>
 */
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>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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