4

Any time a product is updated and saved, its "created_at" entry in the "catalog_product_entity" database table is updated to the format YYYY-DD-MM, but it should keep it as YYYY-MM-DD. The date/time do not change, only the format. It isn't a big problem in itself, but it is creating problems when I attempt to sort products by creation date.

Here is an example:

  • created_at before: 2015-04-10 13:21:09 (YYYY-MM-DD)
  • edit and save product via Magento
  • created_at after: 2015-10-04 13:21:09 (YYYY-DD-MM)

Extra information: It is a Magento 1.9.1 store with the locale set to English (US) and timezone set to Los Angeles. The products from the store were originally imported via Magento's Import/Export feature from a wooCommerce store. Let me know if you need any more info.

  • Did you move your store from one server to another at some point? – brentwpeterson May 31 '15 at 16:07
  • Yes, quite recently. – 1awesomeguy Jun 1 '15 at 6:11
  • Are you on share hosting or dedicated? – brentwpeterson Jun 1 '15 at 14:13
  • Shared server with cPanel. – 1awesomeguy Jun 1 '15 at 19:37
4

you have to use

Mage::getModel('core/date')->gmtDate() 

instead of

$zendDate->getIso()

below is the solution.

open following file : app\code\core\Mage\Eav\Model\Entity\Attribute\Backend\Time\Created.php

and comment out beforeSave() function and replace with following function code.

  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
        $zendDate = Mage::app()->getLocale()->utcDate(null, $date, true, $this->_getFormat($date));

        // Replace -> $zendDate->getIso() with Mage::getModel('core/date')->gmtDate()
        $object->setData($attributeCode, Mage::getModel('core/date')->gmtDate());
    }

    return $this;
}
| improve this answer | |
  • This appears to change the created_at date to the time the product is updated. – 1awesomeguy Jun 10 '15 at 20:10
  • Commenting out the entire else statement appears to solve the issue for me. – 1awesomeguy Jun 10 '15 at 20:26
  • have you checked in database table what value is going there while commenting entire else statment ? – satish Jun 11 '15 at 13:37
  • If you comment out the else statement, the created_at value does not update after editing a product. Creating a new product adds the correct date to created_at. The only downside seems to be that you would need to make this change again if you update your Magento install, and your created_at dates will not update if you change your locale. – 1awesomeguy Jun 12 '15 at 6:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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