I have this grid developed for the custom module. I added the mass delete action which works fine. But the mass Approve/Disapprove actions work only for one value, when I select multiple values I get this error. Please help to resolve this:
Here is the code for the approve function in controller file:
public function massApproveAction() {
$requestIds = $this->getRequest()->getParam('id');
if(!is_array($requestIds)) {
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('adminhtml')->__('Please select reqeust(s)'));
} else {
try {
foreach ($requestIds as $requestId) {
$RequestData = Mage::getModel('cpstest_productcomment/cps')->load($requestId);
$id = $this->getRequest()->getParam('id');
$data = array('comment_status'=>'Approved');
$model = Mage::getModel('cpstest_productcomment/cps')->addData($data);
}
$model->setId($id)->save();
echo "Data updated successfully.";
} catch (Exception $e){
echo $e->getMessage();
}
}
}
1 Answer 1
Everything is correct but at the time of saving data you set all request params in setId method. Please find below line and correct it.
$model->setId($id)->save();
Replace with below code
$model->setId($requestId)->save();
-
Thanks for your respond. With this code I don't get the error any more, but it still saves only one value.bestwebdevs– bestwebdevs2017年04月06日 16:58:05 +00:00Commented Apr 6, 2017 at 16:58
-
Your solution is correct, I made a mistake and put it outside the loop, that's why it was only saving 1 value. Then I put it in the foreach loop and it works great :) Thank you!bestwebdevs– bestwebdevs2017年04月06日 17:34:27 +00:00Commented Apr 6, 2017 at 17:34
Explore related questions
See similar questions with these tags.