www.it-ebooks.info
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
Updating in bulk w<strong>it</strong>h Massactions<br />
When creating our base grid block, we defined a function called<br />
_prepareMassactions(), which provides an easy way of manipulating<br />
multiple records from the grid. In our case, for now, let's just implement<br />
a mass delete action. Perform the following steps to do so:<br />
Chapter 5<br />
1. Open the registry grid block Grid.php, which can be found at app/code/<br />
local/Mdg/Giftregistry/Block/Adminhtml/Registries/.<br />
2. Replace the _prepareMassaction() function w<strong>it</strong>h the following code:<br />
protected function _prepareMassaction(){<br />
$this->setMassactionIdField('ent<strong>it</strong>y_id');<br />
$this->getMassactionBlock()-><br />
setFormFieldName('registries');<br />
}<br />
$this->getMassactionBlock()->addItem('delete', array(<br />
'label' => Mage::helper<br />
('mdg_giftregistry')->__('Delete'),<br />
'url' => $this->getUrl('*/*/massDelete'),<br />
'confirm' => Mage::helper<br />
('mdg_giftregistry')->__('Are you sure?')<br />
));<br />
return $this;<br />
The way mass actions work is by passing a series of selected IDs to our specified<br />
controller action; in this case, the massDelete() action will add code to <strong>it</strong>erate<br />
through the registry collection and delete each of the specified registries. Perform<br />
the following steps:<br />
1. Open the GiftregistryController.php file, which can be found at the<br />
location app/code/local/Mdg/Giftregistry/controllers/Adminhtml/.<br />
2. Replace the blank massDelete() action w<strong>it</strong>h the following code:<br />
…<br />
public function massDeleteAction()<br />
{<br />
$registryIds = $this-><br />
getRequest()->getParam('registries');<br />
if(!is_array($registryIds)) {<br />
Mage::getSingleton('adminhtml/session')-><br />
addError(Mage::helper('mdg_giftregistry')-><br />
__('Please select one or more registries.'));<br />
} else {<br />
try {<br />
[ 151 ]<br />
<strong>www</strong>.<strong>it</strong>-<strong>ebooks</strong>.<strong>info</strong>