Magento Themes and Magento Extensions

Magento : add massDelete action in coupon code

Share

Magento : add massDelete action in coupon code

First override Mage_Adminhtml_Block_Promo_Quote_Grid class and add following code
protected function _prepareMassaction()
{
$this->setMassactionIdField(‘rule_id’);
$this->getMassactionBlock()->setFormFieldName(‘rule’);

$this->getMassactionBlock()->addItem(‘delete’, array(
‘label’    => Mage::helper(‘rule’)->__(‘Delete’),
‘url’      => $this->getUrl(‘*/*/massDelete’),
‘confirm’  => Mage::helper(‘rule’)->__(‘Are you sure?’)
));
return $this;
}

then override Mage_Adminhtml_Promo_QuoteController class and add following code
public function massDeleteAction()
{ //exit;
$rulesIds = $this->getRequest()->getParam(‘rule’);
if(!is_array($rulesIds)) {
Mage::getSingleton(‘adminhtml/session’)->addError(Mage::helper(‘adminhtml’)->__(‘Please select rule(s).’));
} else {
try {
$model = Mage::getModel(‘salesrule/rule’);
foreach ($rulesIds as $rulesId) {
//echo $rulesId; exit;
$model->load($rulesId);
$model->delete();
}
Mage::getSingleton(‘adminhtml/session’)->addSuccess(
Mage::helper(‘adminhtml’)->__(
‘Total of %d record(s) were deleted.’, count($rulesIds)
)
);
} catch (Exception $e) {
Mage::getSingleton(‘adminhtml/session’)->addError($e->getMessage());
}
}

$this->_redirect(‘*/*/index’);
}

Leave a Reply

You must be logged in to post a comment.