2012-06-14 94 views
0

我一直在为magento后端编写一个自定义缺货模块,我有批量操作,导出等工作。但是,当我做任何类型的搜索功能(如在产品名称字段中放入某些东西),并确实尝试切换到下一页(或在该字段中输入特定页面)或页面上显示多少产品。它立即将我重定向到仪表板。Magento - 自定义管理网格问题

任何人都可以指出我正确的方向,哪里的代码是处理这个功能?我将假设其控制器的一部分,但我一直在寻找最后一个小时,现在是时候寻求帮助!

感谢您提供任何帮助!

准备列功能:

protected function _prepareColumns() 
{ 
    $this->addColumn('sku', 
     array(
      'header'=> Mage::helper('catalog')->__('SKU'), 
      'width' => '80px', 
      'index' => 'sku', 
    )); 

    $sets = Mage::getResourceModel('eav/entity_attribute_set_collection') 
     ->setEntityTypeFilter(Mage::getModel('catalog/product')->getResource()->getTypeId()) 
     ->load() 
     ->toOptionHash(); 

    $this->addColumn('set_name', 
     array(
      'header'=> Mage::helper('catalog')->__('Attrib. Set Name'), 
      'width' => '60px', 
      'index' => 'attribute_set_id', 
      'type' => 'options', 
      'options' => $sets, 
    )); 

    $store = $this->_getStore(); 
    if ($store->getId()) { 
     $this->addColumn('custom_name', 
      array(
       'header'=> Mage::helper('catalog')->__('Name in %s', $store->getName()), 
       'index' => 'custom_name', 
     )); 
    } 

    $this->addColumn('name', 
     array(
      'header'=> Mage::helper('catalog')->__('Name'), 
      'index' => 'name', 
    )); 

    $this->addColumn('stock_status', 
     array(
      'header'=> 'Availability', 
      'width' => '60px', 
      'index' => 'stock_status', 
      'type' => 'options', 
      'options' => array('1'=>'In stock','0'=>'Out of stock'), 
    )); 

    $this->addColumn('custom_stock_status', 
    array(
     'header' => 'Custom Stock Status', 
     'width' => '60px', 
     'index' => 'custom_stock_status', 
     'type' => 'options', 
     'editable' => 'true',)); 

    $this->addColumn('eol', 
    array(
     'header'=> Mage::helper('catalog')->__('EoL'), 
     'width' => '20px', 
     'type' => 'checkbox', 
     'index' => 'eol', 
     'onclick' => 'this.value = this.checked ? 1 : 0;', 
     'values' => array('1','2'), 
     'editable' => 'true', 
    )); 

    $store = $this->_getStore(); 
    $this->addColumn('qty', 
     array(
      'header'=> Mage::helper('catalog')->__('Qty'), 
      'width' => '25px', 
      'type' => 'number', 
      'index' => 'qty', 
    )); 

    $this->addColumn('status', 
     array(
      'header'=> Mage::helper('catalog')->__('Status'), 
      'width' => '70px', 
      'index' => 'status', 
      'type' => 'options', 
      'options' => Mage::getSingleton('catalog/product_status')->getOptionArray(), 
    )); 

    $this->addColumn('action', 
     array(
      'header' => Mage::helper('catalog')->__('Action'), 
      'width'  => '90px', 
      'type'  => 'action', 
      'getter'  => 'getId', 
      'actions' => array(
       array(
        'caption' => Mage::helper('catalog')->__('Edit Product'), 
        'url'  => array(
         'base'=>'store_admin/catalog_product/edit', 
         'params'=>array('store'=>$this->getRequest()->getParam('store')) 
        ), 
        'field' => 'id' 
       ) 
      ), 
      'filter' => false, 
      'sortable' => false, 
      'index'  => 'stores', 
    )); 

    $this->addRssList('rss/catalog/notifystock', Mage::helper('catalog')->__('Notify Low Stock RSS')); 

    return parent::_prepareColumns(); 
} 

而且我试图通过属性筛选,我需要为了过滤两次相同属性的输出都为空,没有属性,但也不是。无论如何要做到这一点?

->addAttributeToFilter('eol', array('null' => true), 'left') 
->addAttributeToFilter('eol', array('No' => true)); 

这就是我现在要做的,但是,它丝毫不起作用。两个人都很好!

回答

0

对于CE 1.6.2,这个工作对我来说:

1)在app/code/core/Mage/Adminhtml/Block/Catalog/Product/Grid.php复制到app/code/local/Mage/Adminhtml/Block/Catalog/Product/Grid.php

2)app/code/local/Mage/Adminhtml/Block/Catalog/Product/Grid.php里面添加下面的代码/ _prepareCollection()

下,经过->addAttributeToSelect('type_id');之前if (Mage::helper('catalog')->isModuleEnabled('Mage_CatalogInventory')) {

CODE:

$collection->joinTable('cataloginventory/stock_item', 
'product_id=entity_id', array("stock_status" => "is_in_stock")) 
->addAttributeToSelect('stock_status'); 

3)添加下面的周围线180后 'index' => 'price', ));

CODE:

$this->addColumn('stock_status', 
    array(
     'header'=> 'Stock Status', // this is the title of the column 
     'width' => '60px',   // this is the width of the column 
     'index' => 'stock_status', 
     'type' => 'options', 
     'options' => array('1'=>'In Stock','0'=>'Out Of Stock'), 
    ) 
); 
1
Mage_Adminhtml_Block_Widget_Grid 

有一个方法

_addColumnFilterToCollection($column) 

你可以重写它以实现过滤逻辑为您定制的网格。