If I have understood what you want, which I hope I have. You are looking for a filtered list of products where there is a checkbox for associated product that will be checked when associated and will stay checked even on page reload etc.
For this I would suggest looking at how Magento itself does it and the best place to see this is in the Associated products tab on the product edit screen in the admin section.
Firstly how does Magento assign the current selection to the gird. Well we can see this in the construct of Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Super_Group
with the following lines.
if ($this->_getProduct()->getId()) {
$this->setDefaultFilter(array('in_products'=>1));
}
Here Magento checks for a currenlty set product, Mage::registry('current_product');
, and if we have one then is sets some default filters to the grid.
Now lets look a bit into these filters. It sets that the filter in_products => 1
but what does that actually mean. Well we can see it being used in the function _addColumnFilterToCollection
where here it checks the column for type in_products
and when this is set then it will get the selected products and add them as filters. If you follow were this function is called it should be called at some point as part of the _prepareCollection
code.
$productIds = $this->_getSelectedProducts();
if (empty($productIds)) {
$productIds = 0;
}
if ($column->getFilter()->getValue()) {
$this->getCollection()->addFieldToFilter('entity_id', array('in'=>$productIds));
}
else {
$this->getCollection()->addFieldToFilter('entity_id', array('nin'=>$productIds));
}
Where Magento gets the selected products looks like the following.
protected function _getSelectedProducts()
{
$products = $this->getProductsGrouped();
if (!is_array($products)) {
$products = array_keys($this->getSelectedGroupedProducts());
}
return $products;
}
The column itself is simply added with the rest of the columns in the grid with the following lines.
$this->addColumn('in_products', array(
'header_css_class' => 'a-center',
'type' => 'checkbox',
'name' => 'in_products',
'values' => $this->_getSelectedProducts(),
'align' => 'center',
'index' => 'entity_id'
));
So to summarise we need to do the following.
- Add the column as if it is a normal column in the grid,
- On construct set the default filters,
- During the
_addColumnFilterToCollection
check to see if the column is our in_products
column and add our custom filter.
- ???
- PROFIT!!!
I hope this helps with your development.
You've done what you need to up to wiring in your controller.
First you need to declare a route for your controller(s) in the module config XML:
...
<admin>
...
<routers>
<masscustomstatusses>
<use>admin</use>
<args>
<module>VivasIndustries_MassCustomStatusses</module>
<frontName>masscustomstatusses</frontName>
</args>
</masscustomstatusses>
</routers>
...
</admin>
...
Then build the controller:
<?php
class VivasIndustries_MassCustomStatusses_ControllerController
extends Mage_Adminhtml_Controller_Action
{
public function actionAction()
{
// Update status here
// Can fetch selected items with $this->getRequest()->getParam()
die('Looks like it works');
}
}
I've used your naming convention exactly as you have described, though I doubt that's what you really want. Better to use standard Magento convention, with controller named IndexController
and base action named indexAction
. But you should get the idea.
Clear cache and try to run that mass action. The die
statement should run, and fill in the blanks from there.
NOTE: I should point out that you're doing the same thing twice. You are both extending the sales order grid to add a mass action AND injecting it via event observer. As the article you reference points out, those are 2 different ways to do the same thing. You should choose one of those methods, only.
Best Answer
You can have a selected mass action by default by defining it in your grid block like this:
And you can select all the checkboxes by default like this.
Add a method called
_prepareMassactionColumn
in your grid block with this content.