2

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.

enter image description here

asked Mar 20, 2014 at 12:39

2 Answers 2

7

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:

$this->getSelect()
 ->join(array('rt' => $reviewTable),
 'rt.entity_pk_value = e.entity_id',
 array('rt.review_id', 'review_created_at'=> 'rt.created_at', 'rt.entity_pk_value', 'rt.status_id'))
 ->join(array('rdt' => $reviewDetailTable),
 'rdt.review_id = rt.review_id',
 array('rdt.title','rdt.nickname', 'rdt.detail', 'rdt.customer_id', 'rdt.store_id'));

If you added your column in the review_detail table you need to add it in the second join. Make the code above look like this:

$this->getSelect()
 ->join(array('rt' => $reviewTable),
 'rt.entity_pk_value = e.entity_id',
 array('rt.review_id', 'review_created_at'=> 'rt.created_at', 'rt.entity_pk_value', 'rt.status_id'))
 ->join(array('rdt' => $reviewDetailTable),
 'rdt.review_id = rt.review_id',
 array('rdt.title','rdt.nickname', 'rdt.detail', 'rdt.customer_id', 'rdt.store_id', 'rdt.view_type'));

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 class Mage_Review_Model_Resource_Review_Product_Collection.

Change this:

 case 'rt.review_id':
 case 'rt.created_at':
 case 'rt.status_id':
 case 'rdt.title':
 case 'rdt.nickname':
 case 'rdt.detail':
 $this->getSelect()->order($attribute . ' ' . $dir);
 break;

to this:

 case 'rt.review_id':
 case 'rt.created_at':
 case 'rt.status_id':
 case 'rdt.title':
 case 'rdt.nickname':
 case 'rdt.detail':
 case 'rdt.view_type': //you need to add this 'case'
 $this->getSelect()->order($attribute . ' ' . $dir);
 break;

For filtering modify addAttributeToFilter in the same class. Change this

 case 'rt.review_id':
 case 'rt.created_at':
 case 'rt.status_id':
 case 'rdt.title':
 case 'rdt.nickname':
 case 'rdt.detail':
 $conditionSql = $this->_getConditionSql($attribute, $condition);
 $this->getSelect()->where($conditionSql);
 break;

To this:

 case 'rt.review_id':
 case 'rt.created_at':
 case 'rt.status_id':
 case 'rdt.title':
 case 'rdt.nickname':
 case 'rdt.detail':
 case 'rdt.view_type': //you need to add this 'case'
 $conditionSql = $this->_getConditionSql($attribute, $condition);
 $this->getSelect()->where($conditionSql);
 break;

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:

$this->addColumn('view_type', array(
 'header' => Mage::helper('review')->__('View type'),
 'align' => 'left',
 'width' => '100px',
 'filter_index' => 'rdt.view_type',
 'index' => 'view_type',
 'type' => 'options',
 'options' => array(
 0 => Mage::helper('review')->__('Show in home page'),
 1 => Mage::helper('review')->__('Show in product details page')
 ),
));
answered Mar 20, 2014 at 12:46
13
  • Thanks Marius.. I am looking into this.. I was not expecting quick response and yet I updated my post with an image :) Commented Mar 20, 2014 at 12:49
  • I can see the values now.. in grid but whenever I do filtering based on this newly added column, I am getting this error. Fatal error: Call to a member function getBackend() on a non-object in C:\xampp\htdocs\efk\app\code\core\Mage\Eav\Model\Entity\Abstract.php on line 816 Commented Mar 20, 2014 at 12:54
  • I re-indexed and cleared the cache, still the problem persist. It seems this problem is not related to my posted issue. (not sure) Commented Mar 20, 2014 at 13:02
  • 1
    @Mr_Green. Yes you can. Just declare your column as 'type' => 'options', instead of 'type' => 'text', and add the options parameter as well. Commented Mar 21, 2014 at 8:02
  • 1
    @Mr_Green. Great. I've updated the answer anyway. Commented Mar 21, 2014 at 8:23
0

To remove

Fatal error: Call to a member function getBackend() on a non-object in C:\xampp\htdocs\efk\app\code\core\Mage\Eav\Model\Entity\Abst‌​ract.php on line 816

Add

'filter_index' => 'rdt.view_type' // (your newly added column)

in addColumn

Mr_Green
1,6154 gold badges31 silver badges50 bronze badges
answered Oct 27, 2016 at 9:52

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.