Muhit Shaikh
Muhit Shaikh

Reputation: 23

Adding Stock Status column to Manage Product Grid in Admin

I'm trying to add 'stock status' column to the Admin Manage Product Grid. Stock status is either "In Stock" or "Out of Stock".

Seems like I need to edit Adminhtml/Block/Catalog/Product/Grid.php

I added this line:

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

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

But just prints out Array text....

Upvotes: 2

Views: 1026

Answers (1)

Sanchit Gupta
Sanchit Gupta

Reputation: 3224

Try with following code as mentioned by Marius in this answer.

In Grid.php file find $this->setCollection($collection); and before this code add following code (Join) :

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

And now you can add column like :

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

I hope this will help

Upvotes: 1

Related Questions