Magento日期文本:它来自哪里,如何更改? [英] Magento date text: where does it come from and how can I change it?

查看:80
本文介绍了Magento日期文本:它来自哪里,如何更改?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据我从最近的Magento升级中学到的知识,以及随后的修复工作,请帮助我解决我最大的UI困扰之一:日期.这很愚蠢:

With the knowledge I've learned here from my recent Magento upgrade and ensuing fixing, please help me with one of my biggest UI gripes: the date. It is stupid:

我入侵了核心文件app/code/core/Mage/Adminhtml/Block/Sales/Order/Grid.php,并将"100px"更改为"165px",这阻止了日期的包装.我真的很想将日期从'M n,Y g:i:s A'更改为类似Gmail的日期,如果今天使用'g:i:s a'或如果今天不使用'M n,ga'.如果要显示的日期的年份不是当前年份,我会添加年份.

I hacked the core file app/code/core/Mage/Adminhtml/Block/Sales/Order/Grid.php and changed '100px' to '165px', which prevents the date from wrapping. I'd really love to change the date from 'M n, Y g:i:s A' to something like Gmail uses 'g:i:s a' if today or 'M n, ga' if not today. I'd add in the year if the year of the date to be displayed wasn't the current year.

我看到了为初学者覆盖Magento Admin Controller ,这可能足以让我覆盖核心文件中的_prepareColumns() ,但我真的很想知道如何更改日期!顺便说一句,我删除了整个安装程序,但该日期格式字符串的任何部分都没有显示.

I saw Overriding Magento Admin Controller, for Beginners, which might be enough for me to override _prepareColumns() in the core file, but I'd really like to find out how to change that date! BTW, I grepped the whole install and no part of that date format string shows up.

更新:发现日期字符串格式在lib/Zend/Locale/Data/root.xml中设置,如果您的语言环境不是en_us(文件为空),则可能会被覆盖.为了阐明R.S答案的第一部分,日期"format"不是php date()样式,我尝试过这种样式,但结果却很奇怪.仔细阅读Locale XML文件,我做了一些实验,这些实验在这里:

Update: found that the date string format is set in lib/Zend/Locale/Data/root.xml and may be overridden if your locale is something other than en_us, whose file is empty. To expound upon the first part of R.S's answer, the date "format" is not php date() style, which I tried and got quite strange results. Perusing the Locale XML files, I made a few experiments, which are here:

    $this->addColumn('created_at', array(
        'header' => Mage::helper('sales')->__('Purchased On'),
        'index' => 'created_at',
        'type' => 'datetime',
        'format' => 'MMM d, h:mm a',  // Feb 18, 1:57 PM
        //'format' => Mage::app()->getLocale()->getDateTimeFormat(Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM), 
        //'format' => 'MMM d, y G',
        'width' => '165px', // CKCK: edited to fix date field width was 100px
    ));

致力于制作自定义模块以覆盖块渲染器.所示的R.S代码的第2部分无法正常工作,但他的链接为我提供了一个解决方案.将会再次更新结果.

Working on making a custom module to override the block renderer. Part 2 of R.S's code as shown isn't working, but his links give me a recipe. Will update again with results.

更新: 我尝试(失败)覆盖了Adminhtml大宗销售订单表格(absog).另一个模块EM_DeleteOrder已经覆盖了absog.我搜索了一个没有覆盖absog的替换模块,并发现了一个相对于销售网格具有强大功能的扩展:

Update: I tried (and failed) to override the Adminhtml block sales order grid (absog). Another module, EM_DeleteOrder was already overriding absog. I searched for a replacement module that didn't override absog and found an extension with great powers with respect to the sales grid: MageWorx Enhanced Orders. So I installed that and am hacking their source for the date format I want! I'm happy and done, no more updates to this question.

推荐答案

尝试

$this->addColumn('created_at', array(
     'header' => Mage::helper('sales')->__('Purchased On'),
     'index' => 'created_at',
     'type' => 'datetime', 
     'format'    => 'MMM d, h:mm a',
     'width' => '165px',
));

您也可以使用renderer

$this->addColumn('created_at', array(
     'header' => Mage::helper('sales')->__('Purchased On'),
     'index' => 'created_at',
      //'type' => 'datetime', //remove
      'renderer' = new MageIgniter_FormatDate_Block_Adminhtml_Renderer_Data()
      'width' => '165px',
));

然后创建

class MageIgniter_FormatDate_Block_Adminhtml_Renderer_Data extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Action
{
  public function render(Varien_Object $row)
   {
     return $this->_getValue($row);
   }

   public function _getValue(Varien_Object $row)
   {
     $val = $row->getData($this->getColumn()->getIndex());  // row value
     // need to format $val

     return $val;

   } 
}

请参见

  • Magento Customer Grid - Mask Email address
  • http://www.magentocommerce.com/boards/viewthread/192232/#t420795

这篇关于Magento日期文本:它来自哪里,如何更改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆