I'm trying to access the product grid collection from the product edit page, so that I can find where this currently edited product resides in the product grid collection. Ultimately, I want to provide a previous and next button on the edit page. Here is what I have so far:
<?php
class Tloc_Test_Block_Adminhtml_Catalog_Product_Edit extends Mage_Adminhtml_Block_Catalog_Product_Edit {
protected function _prepareLayout() {
parent::_prepareLayout();
/*
* Get the product_filter param directly from the session
*/
$session = Mage::getSingleton('adminhtml/session');
$gridFilterParams = $session->getData('productGridproduct_filter');
if (!empty($gridFilterParams)) {
$decodedParams = base64_decode($gridFilterParams);
if (!empty($decodedParams)) {
parse_str($decodedParams, $params);
Zend_Debug::dump($params);
}
}
/*
* Get the product_filter param through the Widget_Grid block.
*/
/** @var Mage_Adminhtml_Block_Widget_Grid $gridBlock */
$gridBlock = Mage::getSingleton('core/layout')->createBlock('adminhtml/widget_grid');
$gridBlock->setId('productGrid');
$gridBlock->setSaveParametersInSession(true);
$gridFilterParams = $gridBlock->getParam('product_filter');
if (!empty($gridFilterParams)) {
$decodedParams = base64_decode($gridFilterParams);
if (!empty($decodedParams)) {
parse_str($decodedParams, $params);
Zend_Debug::dump($params);
}
}
die('stop');
return $this;
}
}
Both methods of setting $gridFilterParams
work, but ideally I would like to use the built-in block class.
What I want to do at this point is turn the params that I have into filters on a collection. My first choice would be to have Mage_Adminhtml_Block_Widget_Grid
do this, but I have two problems: 1) I would first need to add Columns to the class, and I'm not sure how to do that, and 2) I'm up against a number of protected
methods.
I could use a bit more of a manual approach and build a new collection myself, and use addAttributeToFilter
to filter the collection, but I'm not sure how well that's going to work with custom grid columns that other modules have added.
Any one have any thoughts?