简体   繁体   English

Magento-自定义管理网格问题

[英]Magento - custom admin grid issue

I've been writing a custom out of stock module for the magento backend, I have mass actions, export etc working. 我一直在为magento后端编写自定义的脱销模块,我有大规模行动,导出等工作。 However when i do any sort of search function (like put something in the product name field) and indeed try to change to the next page (or input a specific page into the field) or how many products appear on a page. 但是,当我执行任何类型的搜索功能(例如在产品名称字段中放入一些内容)并确实尝试切换到下一页(或在该字段中输入特定页面)或页面上出现多少产品时。 It immediately redirects me to the dashboard. 它立即将我重定向到仪表板。

Can anyone point me in the right direction as to where the code is that handles this function? 谁能向我指出处理此功能的代码的正确方向? I'm going to assume its part of the controller, but i've been searching for the last hour and is now time to ask for help!! 我将假设它是控制器的一部分,但是我一直在搜索最后一个小时,现在该该寻求帮助了!!

Thanks for any help you can provide! 感谢您的任何帮助,您可以提供!

Prepare columns function: 准备列功能:

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();
}

Furthermore i'm trying to filter by an attribute, I need to filter the same attribute twice in order to output both null and no attributes, but not yes. 此外,我试图按属性进行筛选,我需要对同一属性进行两次筛选,以便同时输出null和no属性,但不是。 Is there anyway to do this? 反正有这样做吗?

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

This is what i'm trying to do at the moment, however, it doesn't work in the slightest. 这是我目前正在尝试做的事情,但是,它丝毫不起作用。 Both work individually fine! 两者都可以单独工作!

Mage_Adminhtml_Block_Widget_Grid  

has a method 有一种方法

_addColumnFilterToCollection($column)

You can override it to implement filtering logic for your custom grid. 您可以覆盖它以为您的自定义网格实现过滤逻辑。

For CE 1.6.2, this worked for me: 对于CE 1.6.2,这对我有用:

1) Copy over app/code/core/Mage/Adminhtml/Block/Catalog/Product/Grid.php to app/code/local/Mage/Adminhtml/Block/Catalog/Product/Grid.php 1)复制到app/code/local/Mage/Adminhtml/Block/Catalog/Product/Grid.php上的app/code/core/Mage/Adminhtml/Block/Catalog/Product/Grid.php app/code/local/Mage/Adminhtml/Block/Catalog/Product/Grid.php

2) add the code below from app/code/local/Mage/Adminhtml/Block/Catalog/Product/Grid.php inside/under _prepareCollection() 2)在_prepareCollection()内/下从app/code/local/Mage/Adminhtml/Block/Catalog/Product/Grid.php添加以下app/code/local/Mage/Adminhtml/Block/Catalog/Product/Grid.php

AFTER ->addAttributeToSelect('type_id'); 之后->addAttributeToSelect('type_id'); and before if (Mage::helper('catalog')->isModuleEnabled('Mage_CatalogInventory')) { 之前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) Add the below around line 180 after 'index' => 'price', )); 3)在'index' => 'price', ));之后在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'),
    )
);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM