在magento中设置质量操作复选框可见性的条件

时间:2014-04-23 17:17:34

标签: php magento checkbox

我有一个magento模块,我正在开发用于将产品导入magento。 我有一个网格,用户可以选择他的产品,然后全部导入(Mass Action)。 如果用户已在列表中导入了产品,则表明它已在网格中显示,但用户不应选择它(选中它的产品复选框)以避免重新导入产品。

我的问题是,如何为批量操作复选框可见性添加条件?

这是我的网格_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;
}

任何人的帮助?

2 个答案:

答案 0 :(得分:1)

嘿伙计你可以根据你的要求使用下面的代码

 $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 :(得分:0)

我不确定如何“隐藏”您想要的复选框,但您可以预先选中复选框(在您的情况下尚未导入的复选框)

为此,请在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 '';
    }

}