0

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:

enter image description here

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(); 
 }
 }
}
asked Apr 6, 2017 at 0:24

1 Answer 1

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();
Teja Bhagavan Kollepara
3,8275 gold badges33 silver badges69 bronze badges
answered Apr 6, 2017 at 6:25
2
  • Thanks for your respond. With this code I don't get the error any more, but it still saves only one value. Commented 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! Commented Apr 6, 2017 at 17:34

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.