0

below code is _prepareMassaction() in grid.php

protected function _prepareMassaction()
    {
         $this->setMassactionIdField('slideshow_id');
         $this->getMassactionBlock()->setFormFieldName('slideshow');

        $this->getMassactionBlock()->addItem('delete', array(
             'label'    => Mage::helper('slideshow')->__('Delete'),
             'url'      => $this->getUrl('*/*/massDelete'),

        ));

     $statuses = Mage::getSingleton('slideshow/status')->getOptionArray();

    //print_r($statuses); die;

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

Below code in massStatusAction() in my controller.

public function massStatusAction()
    {
        $ids = $this->getRequest()->getParam('slideshow');
        //print_r($ids); die;
        if(!is_array($ids)) {
            Mage::getSingleton('adminhtml/session')->addError($this->__('Please select checkbox'));
        } else {
            try {
                foreach ($ids as $id) {

                    //print_r($id); die;
                   Mage::getSingleton('slideshow/slideshow')
                        ->load($id)
                        ->setStatus($this->getRequest()->getParam('status'))
                        ->setIsMassupdate(true)
                        ->save();
                }
                $this->_getSession()->addSuccess(
                    $this->__('Total of %d record(s) were successfully updated', count($ids))
                );
            } catch (Exception $e) {
                $this->_getSession()->addError($e->getMessage());
            }
        }
        $this->_redirect('*/*/index');
    }

When i changes action from disable to enable it successfully changes. but again when i change status from enable to disable. it not changes my status.

2
  • What is the input you are passing at $this->getRequest()->getParam('status'), it should be 1=enable and 2=disable. Most people assume 0 is for disable, not sure what is in your case
    – Duke
    Commented May 12, 2016 at 12:00
  • $this->addColumn('status', array( 'header' => Mage::helper('slideshow')->__('Status'), 'align' => 'left', 'width' => '80px', 'index' => 'status', 'type' => 'options', 'options' => array( 1 => 'Enable', 0 => 'Disable', ) )); Commented May 12, 2016 at 12:02

2 Answers 2

0

As per your comment, its obvious you are passing 0 for disable. In Magento this should work with disable value as 2

Your code can be rewrite as per below

$this->addColumn('status', array( 'header' => Mage::helper('slideshow')->__('Status'), 'align' => 'left', 'width' => '80px', 'index' => 'status', 'type' => 'options', 'options' => array( 1 => 'Enable', 2 => 'Disable', ) ));
2
  • @duke..from which php file ...getParam('status') is coming..it grid.php or form.php --> setStatus($this->getRequest()->getParam('status')) Commented May 12, 2016 at 12:23
  • Usually it comes from _prepareColumns functions should be in Grid.php
    – Duke
    Commented May 12, 2016 at 12:28
0

Add this method to app\code\community\Dolphin\Slideshow\Block\Adminhtml\Slideshow\Grid.php

protected function _prepareMassaction()
{
    $this->setMassactionIdField('slideshow_id');
    $this->getMassactionBlock()->setFormFieldName('status');

    $this->getMassactionBlock()->addItem('enable_slides', array(
        'label'    => Mage::helper('slideshow')->__('Enable Slides'),
        'url'      => $this->getUrl('*/*/massEnable'),
    ));
    $this->getMassactionBlock()->addItem('disable_slides', array(
        'label'    => Mage::helper('slideshow')->__('Disable Slides'),
        'url'      => $this->getUrl('*/*/massDisable'),
    ));

    return $this;
}

Add this actions to app\code\community\Dolphin\Slideshow\controllers\Adminhtml\IndexController.php

public function massEnableAction()
{
    $slideIds = $this->getRequest()->getParam('status');
    if(!is_array($slideIds)) {
        Mage::getSingleton('adminhtml/session')->addError(Mage::helper('slideshow')->__('Please select Slide(s)'));
    } else {
        try {
            foreach ($slideIds as $slideId) 
            {
                $slidesModelInner = Mage::getModel('slideshow/slideshow')->load($slideId);
                $slidesModelInner->setStatus(1)->save();
            }
            Mage::getSingleton('adminhtml/session')->addSuccess(
                Mage::helper('slideshow')->__('Total of %d slides(s) were successfully enabled',count($slideIds))
            );
        } catch (Exception $e) {
            Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
        }
    }
    $this->_redirect('*/*/index');
}
public function massDisableAction()
{
    $slideIds = $this->getRequest()->getParam('status');
    if(!is_array($slideIds)) {
        Mage::getSingleton('adminhtml/session')->addError(Mage::helper('slideshow')->__('Please select Slide(s)'));
    } else {
        try {
            foreach ($slideIds as $slideId) 
            {
                $slidesModelInner = Mage::getModel('slideshow/slideshow')->load($slideId);
                $slidesModelInner->setStatus(0)->save();
            }
            Mage::getSingleton('adminhtml/session')->addSuccess(
                Mage::helper('slideshow')->__('Total of %d slides(s) were successfully disabled',count($slideIds))
            );
        } catch (Exception $e) {
            Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
        }
    }
    $this->_redirect('*/*/index');
}

This will look like this:

enter image description here

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.