Set the condition for the visibility of bulk action flags in magento

I have a magento module that I am developing to import products into magento. I have a grid in which the user can select their products and import them (mass action). If the user has products already imported into the list, they are displayed in the grid, but the user should not select it (check the product box) to avoid re-importing the product.

My question is: how can I add a condition for the visibility of bulk action flags?

Here is my Grid _prepareMassaction:

protected function _prepareMassaction()
{
    $this->setMassactionIdField('sku');
    $this->getMassactionBlock()->setFormFieldName('import');
    $this->getMassactionBlock()->setUseSelectAll(false);
    $this->getMassactionBlock()->addItem('import', array(
        'label' => Mage::helper('import')->__('Import'),
        'url' => $this->getUrl('*/*/massImport'),
        'confirm' => Mage::helper('import')->__('Are you sure?')
    ));

    return $this;
}

Any help to anyone?

+4
source share
2 answers

,

 $ids = $this->getRequest()->getParam('sliders');
    if (!is_array($ids)) {
        $this->_getSession()->addError($this->__('Please select items.'));
    } else {
        try {
            foreach ($ids as $id) {
                $model = Mage::getSingleton('sliders/sliders')->load($id);
                $model->delete();
            }

            $this->_getSession()->addSuccess(
                $this->__('Total of %d record(s) have been deleted.', count($ids))
            );
        } catch (Mage_Core_Exception $e) {
            $this->_getSession()->addError($e->getMessage());
        } catch (Exception $e) {
            $this->_getSession()->addError(Mage::helper('contact')->__('An error occurred while mass deleting contacts. Please review log and try again.'));
            Mage::logException($e);
            return;
        }
    }
    $this->_redirect('*/*/index');
+1

, "" , (, )

, Grid.php:

protected $_massactionBlockName = 'yourmodule/adminhtml_index_grid_massaction';

... /Block/Adminhtml/Index/Grid/Massaction.php :

class YourPackage_YourModule_Block_Adminhtml_Index_Grid_Massaction extends Mage_Adminhtml_Block_Widget_Grid_Massaction
{

    public function getSelectedJson()
    {
        //$gridIds = $this->getParentBlock()->getCollection()->getAllIds();
        $gridIds = getTheIdsYouWantHere();
        if(!empty($gridIds)) {
            return join(",", $gridIds);
        }
        return '';
    }

}
0

Source: https://habr.com/ru/post/1537759/


All Articles