添加库存状态列以在管理员中管理产品网格

Adding Stock Status column to Manage Product Grid in Admin

我正在尝试将 'stock status' 列添加到管理员管理产品网格。库存状态为 "In Stock" 或 "Out of Stock"。

看来我需要编辑 Adminhtml/Block/Catalog/Product/Grid.php

我添加了这一行:

$this->addColumn('stock',
        array(
            'header'=> Mage::helper('catalog')->__('Stock Avail.'),
            'width' => '70px',
            'index' => 'status',
            'type'  => 'options',

            'options' => Mage::getSingleton('cataloginventory/source_stock')->toOptionArray()

但只是打印出数组文本....

尝试使用 Mariusthis 回答中提到的以下代码。

Grid.php 文件中找到 $this->setCollection($collection); 并在此代码之前添加以下代码 (Join) :

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

现在您可以添加如下列:

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

希望对您有所帮助