DateTime issue in magento - magento

There is an issue in my magento site in displaying date. In Database table, Date is stored with value '2013-06-12 14:14:57' and when date is displaying in admin section it becomes 'Jun 12, 2013 10:14:57 PM', it is increasing 8 hours by the original value stored in database.
Below is the code which i am using
$this->addColumn('created_at', array(
'header' => Mage::helper('sales')->__('Purchased On'),
'index' => 'created_at',
'type' => 'datetime',
'width' => '100px',
));
Can anyone tell me why this happen?

Related

Magento 1.9: sort grid view

I've added a column to my gridview and it suppose to show remaining days of an event.
$this->addColumn('calculate_days', array(
'header' => Mage::helper('myodule')->__('Remaining'),
'type' => 'options',
'width' => '200px',
'options' => $options,
'frame_callback' => array($this, 'getRemaining'),
'filter_condition_callback' => array($this, '_calculateFilter')
));
getRemaining method:
public function getRemaining($value, $row, $column)
{
// some calculation to find out remaining days based on some conditions
return $days;
}
If I don't specify the index key, clicking on the Remaining column does not work. So I've added index key to addColumn like bellow:
$this->addColumn('calculate_days', array(
'header' => Mage::helper('myodule')->__('Remaining'),
'type' => 'options',
'width' => '200px',
'index' => 'created_at',
'options' => $options,
'frame_callback' => array($this, 'getRemaining'),
'filter_condition_callback' => array($this, '_calculateFilter')
));
now the sort is WORK but not correctly. when I specify the index, sort applied by index column(in this case will sort by created_at) but I want to sort by remaining days.
what should I do to solve this problem? or is there any sort callback?
Why don't you add this value as a new field in this grid? And then update this field values each day by a cronjob.
Then you will have in a native way the items sorted and also you avoid to recalculate each value each time you filter o see this grid.
Hope it helps,
Regards

How to add column Date Shipped to Sales Order Grid magento

I'm stuck with adding column to sales order grid from shipment grid.
The problem is: "Purchased On" in DB has name "created_at", "Date Shipped" has also name "created_at", so when I join "created_at" from "sales_flat_shipment_grid" I see purchased on date only with name date shipped.
I'm using this code:
in _prepareCollection()
$collection->getSelect()->joinLeft(array('sfsg'=>'sales_flat_shipment_grid'),'sfsg.order_increment_id=main_table.increment_id',array('sfsg.created_at'));
and in _prepareColumns()
$this->addColumn('created_at', array(
'header' => Mage::helper('sales')->__('Date Shipped'),
'index' => 'created_at',
'type' => 'datetime',
'filter_index'=>'sfsg.created_at',
));
Could you please help me with this?
After few hours of trying I've found answer in my case it is:
in _prepareCollection() add
$collection->getSelect()->joinLeft(array('sfsg'=>$resource->getTableName('sales_flat_shipment_grid')),'sfsg.order_increment_id=main_table.increment_id',array(
'shiped' => new Zend_Db_Expr('group_concat(sfsg.created_at SEPARATOR " | ")'),
));
and in _prepareColums()
$this->addColumn('shiped', array(
'header' => Mage::helper('sales')->__('Date Shipped'),
'index' => 'shiped',
'type' => 'datetime',
'filter_index'=>'sfsg.created_at',
));

Magento Reviews Management - Edit Grid

In magento admin I can only see up to 50 characters of review text. How can I edit template etc so I can view the whole review text?
Thanks
you need to override the _prepareColumns() function under Mage_Adminhtml_Block_Review_Grid
there is below code section
$this->addColumn('detail', array(
'header' => Mage::helper('review')->__('Review'),
'align' => 'left',
'index' => 'detail',
'filter_index' => 'rdt.detail',
'type' => 'text',
'truncate' => 50,
'nl2br' => true,
'escape' => true,
));
in which truncate is used, you need to increase the limit.

How to customize the database value in magento customer grid

I created new magento grid for customer module for special purpose.
In that there have a column usertype it have value as 0,1,2.
It will displayed in customer grid page as 0,1,2.
But i need to display if value is,
0 -> Inactive
1 -> Activated
2 -> Baned
How can i dothis?
This is my code grid.php in _prepareColumns() :
$this->addColumn('usertype', array(
'header' => Mage::helper('customer')->__('Usertype'),
'width' => '150',
'index' => 'usertype'
));
If this is possible in magento.
if your greed implements Mage_Adminhtml_Block_Widget_Grid I suggest you to modify
you addColumn call to
$this->addColumn('usertype',
array(
'header'=> Mage::helper('customer')->__('Usertype'),
'width' => '150px',
'index' => 'usertype',
'type' => 'options',
'options' => $values
));
Where $values should be formatted as
array( 'value_id' => 'value_label')
Now you have dropdown created with values.
Then update _prepareCollection() function and add attribute values to customer grid collection
$collection->joinAttribute('usertype', 'customer/usertype', 'entity_id', null, 'left');
I got the solution from this
By using rendere will help to load vlaues to each row.

Magento 1.7 - filter on date part of a timestamp column in grid

I have the following column in a grid:
$this->addColumn('order_date',
array(
'header'=> $this->__('Date'),
'align' =>'left',
'width' => '100px',
'index' => 'order_date',
'type' => 'date',
'filter_index' => 'orders_alias.created_at'
)
);
Example data looks like this: http://imageshack.us/photo/my-images/502/scr028.jpg/
When filtering on date 13 Oct 2012 no rows are found. This makes sense because it is a timestamp column. http://imageshack.us/photo/my-images/29/scr029.jpg/
How can I do this to use the Magento date from/to selector and select 13/10/2012 and show all rows
with this date regardless of the time part?
This a bug that only shows up when you are trying to show a value as date and database column is datetime or timestamp.
It happens because date is changed to YYYY-MM-DD HH:MM:SS and HH:MM:SS being 00:00:00 for date from and to. The date to should be set to 23:59:59.
One way to do this would be to change the code in app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Filter/Date.php to support this. In setValue function just change
EDIT: This first solution would require changes in Datetime.php getValue (removing code that adds one day and removes one second) as well and because you shouldn't change core code the second solution would definitely be the preferred one.
$value['to'] = $this->_convertDate($value['to'], $value['locale']);
to
$value['to'] = $this->_convertDate($value['to'], $value['locale'])->addDay(1)->subSecond(1);
Since this changes the functionality of all the filters a better solution would be to change your local code:
$this->addColumn('order_date',
array(
'header'=> $this->__('Date'),
'align' =>'left',
'width' => '100px',
'index' => 'order_date',
'type' => 'datetime',
'filter_index' => 'orders_alias.created_at',
'frame_callback' => array( $this,'styleDate' )
)
// ...
public function styleDate( $value,$row,$column,$isExport )
{
$locale = Mage::app()->getLocale();
$date = $locale->date( $value, $locale->getDateFormat(), $locale->getLocaleCode(), false )->toString( $locale->getDateFormat() ) ;
return $date;
}
This will remove time part from being shown in the grid's fields but will let you use filters the way you described above.

Resources