开发者

Impossible to roll back to "Use Default" on date fields

I have just reported a bug to Magento (http://www.magentocommerce.com/bug-tracking/issue?issue=11842) and I was wondering if someone here ever saw this problem and found a solution.

Here is the thing :

For any date type field in product edit page in backend :

1- Switch to a store view

2- Uncheck "Use default" (for a date field)

3- Chose a date

4- Save product and continue edit

5- Recheck "Use default"

6- Save product and continue edit

"Use default" checkbox stays unchecked :(

Field value is empty and editable :(

I've tried several googling and didn't find any answer that work开发者_StackOverflow社区s.

Many thanks for sharing I you have a clue.


This has been fixed in CE 1.5 Here is how to fix it for previous versions.

Edit app/code/core/Mage/Eav/Model/Entity/Attribute/Backend/Datetime.php

Replace

public function beforeSave($object)
{
    $attributeName = $this->getAttribute()->getName();
    $_formated = $object->getData($attributeName . '_is_formated');
    if (!$_formated && $object->hasData($attributeName)) {
        try {
            $value = $this->formatDate($object->getData($attributeName));
        } catch (Exception $e) {
            throw new Exception("Invalid date.");
        }
        $object->setData($attributeName, $value);
        $object->setData($attributeName . '_is_formated', true);
    }
}

with

public function beforeSave($object)
{
    $attributeName = $this->getAttribute()->getName();
    $_formated = $object->getData($attributeName . '_is_formated');
    if (!$_formated && $object->hasData($attributeName)) {
        try {
            $value = $this->formatDate($object->getData($attributeName));
        } catch (Exception $e) {
            throw new Exception("Invalid date.");
        }

        if (is_null($value)) {
            $value = $object->getData($attributeName);
        }            

        $object->setData($attributeName, $value);
        $object->setData($attributeName . '_is_formated', true);
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜