On the webguys page is a german article about this problem: http://www.webguys.de/magento/turchen-23-pimp-my-produktgrid/
Nicht alle unsere Änderungen werden von Magento übernommen, zum Beispiel funktioniert die Sortierung und Filterung der neuen Attribute nicht.
Das liegt daran, dass unsere Änderungen nach dem Aufruf von _prepareCollection()
, in dem die Spalteninfos an die Collection übergeben werden, stattfinden.
Translation:
Not all changes are made by magento, e.g. sorting and filtering of the new attributes doesn't work.
That's because they are made after the _prepareCollection()
call, where the informations about the columns are passed to the collection.
protected function _callProtectedMethod($object, $methodName) {
$reflection = new ReflectionClass($object);
$method = $reflection->getMethod($methodName);
$method->setAccessible(true);
return $method->invoke($object);
}
protected function _modifyProductGrid(Mage_Adminhtml_Block_Catalog_Product_Grid $grid) {
$this->_addUpdatedAtColumn($grid);
$this->_addColorColumn($grid);
$this->_removeColumn($grid, 'set_name');
$this->_removeColumn($grid, 'visibility');
// reinitialisiert die Spaltensortierung
$grid->sortColumnsByOrder();
// reinitialisiert die Sortierung und Filter der Collection
$this->_callProtectedMethod($grid, '_prepareCollection');
}
More in the post. I think the source code is quite self explaining and if not, use google (if you don't understand german ;-))
The normal behaviour for the grid checkbox is to bind a js event to it, and action the checkbox check/uncheck. Normally this would be to populate a hidden field with the selected values, and then that field is what gets posted to your controller action.
See varienGrid.prototype /js/mage/adminhtml/grid.js : (this.checkboxCheckCallback) and also setCheckboxChecked method in that class.
For this reason the checkbox element generally do not get a name assigned to it, which you can see if you view your element properties.
This is thus the reason why you cannot get the selected options in your post action, since elements with no name will not post in the form, and you most likely do not have the required callback set to deal with the check/uncheck of the box. Using the callback js, you could also effect other actions in your gui, to enhance the user experience.
However, looking at your usage requirements, you may just get away with setting a name for the checkbox element, which will then post the data to your action.
Thus if you adjust your element definition to this (adding in the 'field_name' property), you will get your data in an array called 'selectedproducts'
$this->addColumn('in_category', array(
'header_css_class' => 'a-center',
'type' => 'checkbox',
'values' => $this->_getSelectedProducts(),
'align' => 'center',
'index' => 'entity_id',
'name' => 'in_category',
'field_name' => 'selectedproducts[]'
));
Hope that helps.
Best Answer
Overview
After scratching my head, i finally built a module.
Models
Created a model that extends the Category model to avoid having a custom entity.
Observers
This observer adds our new products tab and serialized grid in the category management page and listens to the
adminhtml_catalog_category_tabs
event.This observer saves the category-essentials product relation on category save and listens to the
catalog_category_save_after
event.Code
Block
controllers
etc
Helper
Model
sql
adminthml
frontend