1

How to Add Custom MassAction In Controller For Status?

My Status Having

  1. Accepted
  2. Not Process
  3. Rejected
  4. Re-Offer

So how can I Get These Values in change status in MassAction? I Put Default MassAction But Getting "Enable" And "Disable" Value for the Status.

MassAction

public function massStatusAction()
{

    $pricenegotiateIds = (array)$this->getRequest()->getParam('id');
    $pricenegotiateModel  = Mage::getModel('pricenegotiate/pricenegotiate')->load($pricenegotiateIds);
        print_r($pricenegotiateIds);exit;
    $status     = (int)$this->getRequest()->getParam('status'); //get Status
    if($status==2)
    {
        $couponcode=(rand(10,100));
        echo $couponcode."<br>";
    }
    print_r($status);die;
    //your logic
}
1
  • Can you please add the code which you have in your module
    – John
    Commented Apr 10, 2017 at 7:40

1 Answer 1

2

in your Grid.php

protected function _prepareMassaction()
{
    $statuses = array(
        0=>'Accepted',
        1=>'Not Process',
        2=>'Rejected',
        3=>'Re-Offer'
    );

    array_unshift($statuses, array('label'=>'', 'value'=>''));
    $this->getMassactionBlock()->addItem('status', array(
         'label'=> $this->__('Change status'),
         'url'  => $this->getUrl('*/*/massStatus', array('_current'=>true)),
         'additional' => array(
                'visibility' => array(
                     'name' => 'status',
                     'type' => 'select',
                     'class' => 'required-entry',
                     'label' => $this->__('Status'),
                     'values' => $statuses
                 )
         )
    ));

    return $this;
}

in your controller

public function massStatusAction()
{
    $status     = (int)$this->getRequest()->getParam('status'); //get Status

    //your logic
}

For reference check below core files

app/code/core/Mage/Adminhtml/Block/Catalog/Product/Grid.php

and

app/code/core/Mage/Adminhtml/controllers/Catalog/ProductController.php

5
  • Excellent Bro... +1 For your Answer. Commented Apr 11, 2017 at 5:45
  • But in the database status value can not change after submit button clicked. so can you pls how to fix that ? Commented Apr 11, 2017 at 5:51
  • add your massStatusAction() @H_Parekh Commented Apr 11, 2017 at 6:53
  • I Put massStatusAction() in the question, so pls see the question. Commented Apr 11, 2017 at 7:09
  • you have not set the status for your pricenegotiateModel then how it will change the status @H_Parekh Commented Apr 11, 2017 at 7:16

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.