【问题标题】:Set condition for mass action checkbox visibility in magento在 magento 中设置批量操作复选框可见性的条件
【发布时间】:2014-06-08 16:30:03
【问题描述】:

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

我的问题是,如何为大规模行动复选框的可见性添加条件?

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

有什么帮助吗?

【问题讨论】:

    标签: php magento checkbox


    【解决方案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');
    

    【讨论】:

    • 这段代码不是为了我要找的东西,此外,它是为了在行选择之​​后执行一些操作(选中它的复选框)。
    【解决方案2】:

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

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

    【讨论】:

      猜你喜欢
      • 2011-08-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-27
      • 2018-01-27
      相关资源
      最近更新 更多