2

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:

enter image description here

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.

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.


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
    ));

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.


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.

Community
  • 1
  • 1
Krista K
  • 21,503
  • 3
  • 31
  • 43

1 Answers1

2

Try

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

You could also use 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',
));

Then create

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;

   } 
}

See

Community
  • 1
  • 1
MagePal Extensions
  • 17,646
  • 2
  • 47
  • 62
  • Your exact code crashes the sales order grid, however, you've got me on the correct path, so marked `accepted`. Thanks! – Krista K Feb 19 '13 at 00:12
  • I was able to make the change to core file (as I updated above) but am stuck trying to make adminhtml module. Please check out http://stackoverflow.com/questions/14948525 ? Thanks! – Krista K Feb 19 '13 at 01:52