我覆盖class My_CategoryFilters_Block_Adminhtml_Catalog_Category_Tab_Product extends Mage_Adminhtml_Block_Widget_Grid
并将“可见性”列添加到_prepareCollection 和_prepareColumns。每当我尝试过滤时,网格都不会刷新。
我读到Grid 没有出现在 Magento 的自定义管理模块中和Magento Grid Container Block not loading grid。两者都建议创建一个重载的控制器。有一点 Magento 经验的人可以解释一下我所缺少的吗?
提前致谢。
编辑:从代码中删除了“渲染器”和“控制器”。
这是树的样子:
CategoryFilters
├── Block
│ └── Adminhtml
│ └── Catalog
│ └── Category
│ └── Tab
│ └── Product.php
├── Core
│ └── etc
│ └── config.xml
└── etc
这是我的代码:
protected function _prepareCollection()
{
if ($this->getCategory()->getId()) {
$this->setDefaultFilter(array('in_category'=>1));
}
$store = $this->_getStore();
$collection = Mage::getModel('catalog/product')->getCollection()
->addAttributeToSelect('name')
->addAttributeToSelect('sku')
->addAttributeToSelect('price')
->addAttributeToSelect('store_id')
->addStoreFilter($this->getRequest()->getParam('store'))
->joinField('position',
'catalog/category_product',
'position',
'product_id=entity_id',
'category_id='.(int) $this->getRequest()->getParam('id', 0),
'left')
->joinAttribute('visibility', 'catalog_product/visibility', 'entity_id', null, 'inner', $store->getId());
;
$this->setCollection($collection);
$this->getCollection()->addWebsiteNamesToResult();
if ($this->getCategory()->getProductsReadonly()) {
$productIds = $this->_getSelectedProducts();
if (empty($productIds)) {
$productIds = 0;
}
$this->getCollection()->addFieldToFilter('entity_id', array('in'=>$productIds));
}
return parent::_prepareCollection();
}
protected function _prepareColumns()
{
$this->addColumn('visibility', array(
'header' => Mage::helper('catalog')->__('Visibility'),
'width' => '100',
'sortable' => false,
'index' => 'visibility',
'type' => 'options',
'options' => Mage::getModel('catalog/product_visibility')->getOptionArray(),
#'renderer' => new Rogue_CategoryFilters_Block_Adminhtml_Renderer_Visibility()
));
}