0

When looking at my customers created, I am showing a customer created on January 4, that was created on April 1.... at first I thought it was an April fools joke (no, seriously, I didn't), and then I noticed that there were some other date swaps as well

I found an answer here that gave me an idea of what is needed, but it leaves more questions. The answer references an Inchoo blog post that has me completely lost as to where to begin with the edits.

Can anyone clarify the file structure for this specific edit and what I would need to do... the changes I tried using the blog post above created no change in functionality of the site, or customer save function, so I know I did it wrong, but at least that is better than breaking the site completely!

the core function the post seems to be editing can be found at \app\code\core\Mage\Eav\Model\Entity\Attribute\Backend\Time\Created.php, there are 3 functions on this file, and 2 are edited... so if I could just move it to a local folder (like modifying a theme file) that would be awesome as well (can I just move it to \app\code\local\Mage\Eav\Model\Entity\Attribute\Backend\Time\Created.php and make the edits there?)

1 Answer 1

1

Okay, nobody replied so I will post the answer

You CAN copy the file to \app\code\local\Mage\Eav\Model\Entity\Attribute\Backend\Time\Created.php and modify the functions necessary, once modified and uploaded it will take precedence over the core file and no worries about being overwritten during an update (though, if they update and that file is part of it, I would hope it would be to fix the problem)

the update to that file is here, so nobody needs to hop pages to find it

Replace beforeSave with this:

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 {
        // ADD THIS
        $date = strtotime($date);

        // convert to UTC
        $zendDate = Mage::app()->getLocale()->utcDate(null, $date, true, $this->_getFormat($date));
        $object->setData($attributeCode, $zendDate->getIso());
    }

    return $this;
}

This also needs to be corrected on the way out of the database. Replace afterLoad with this:

public function afterLoad($object)
{
    $attributeCode = $this->getAttribute()->getAttributeCode();
    $date = $object->getData($attributeCode);

    // ADD THIS
    if (!is_null($date)) {
        $date = strtotime($date);
    }

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

    parent::afterLoad($object);

    return $this;
}

credit to @Tyler V. for the fix

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.