我有一个正在开发的magento模块,用于将产品导入magento。我有一个网格,用户可以在其中选择他的产品,并导入所有产品(批量操作)。如果用户已经在列表中导入了产品,那么它会显示在网格中,但用户不应该选择它(选中它的产品复选框)以避免重新导入产品。
我的问题是,如何添加大规模操作复选框可见性的条件?
这是我的网格的_prepareAssact:
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;
}
有人帮忙吗?
嘿,伙计,你可以根据你的要求使用下面的代码
$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');
我不知道如何"隐藏"您想要的复选框,但您可以预先选择复选框(在您的情况下,是以前尚未导入的复选框)
要做到这一点,请将其添加到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 '';
}
}