I added a column to review_detail
table i.e view_type
through PhpMyAdmin
and assigned a default value 0
to all the reviews.
I am trying to add the same column for filtering to the All reviews
grid which can be visited from Catalog -> Reviews and Ratings -> Customer Reviews -> All Reviews
.
For just testing purpose, I am altering the core/Mage
files in Mage/Adminhtml/Block/Review/Grid.php
— line ~ 130
:
$this->addColumn('view_type', array(
'header' => Mage::helper('review')->__('View type'),
'align' => 'left',
'width' => '100px',
'filter_index' => 'rdt.view_type',
'index' => 'view_type',
'type' => 'text',
'truncate' => 50,
'escape' => true,
));
By adding the above code, I can see my newly added filtering column name in the All reviews
grid of admin panel but I can't filter or see the default assigned values to any review.
Best Answer
The value of your column is not joined automatically to the collection listed in the grid.
The collection listed in the grid is an instance of
Mage_Review_Model_Resource_Review_Product_Collection
.You need to modify the method
_joinFields
in that class. (For test purposes of course. When you are sure it works do it the proper Magento way by rewriting the class.).By default the fields are joined this way:
If you added your column in the
review_detail
table you need to add it in the secondjoin
. Make the code above look like this:The code above will let you see the values in your custom column.
In order to make sorting to work you need to modify the method
setOrder
in the same classMage_Review_Model_Resource_Review_Product_Collection
.Change this:
to this:
For filtering modify
addAttributeToFilter
in the same class. Change thisTo this:
Damn...a lot of work for a simple column. I hope this gets re-factored in 2.0.
[EDIT]
To add your new column as an options column declare it like this: