I have successfully been able to get whether a product is 'In Stock' or 'Out of Stock' in the Magento admin product grid using an observer in the way set out below. However when I try to filter by 'In Stock' or 'Out of Stock' it simply doesn't work.

I believe this is to do with the filter index and ensuring that the collection associates the stock column with the joined table for filtering. I'm unsure how to get this working - if anyone has any suggestions it would be much appreciated. I have set out my existing code below:




class Creare_Stockcolumn_Model_Observer {

public function onBlockHtmlBefore(Varien_Event_Observer $observer) {
    $block = $observer->getBlock();
    if (!isset($block)) return;

    switch ($block->getType()) {
        case 'adminhtml/catalog_product_grid':
                       'header'=> 'Stock Status',
                       'width' => '60px',
                       'index' => 'stock_status',
                       'type'  => 'options',
                       'options' => array('1'=>'In Stock','0'=>'Out Of Stock'),

public function onEavLoadBefore(Varien_Event_Observer $observer) {
    $collection = $observer->getCollection();
    $collection->joinTable( array('inv' => 'cataloginventory/stock_item'), 'product_id = entity_id', array("stock_status" => "is_in_stock") )->addAttributeToSelect('stock_status');


2 Answers 2


How about adding the stock status to the grid and using that to search with? This link on magento.SE from a few days ago will help you add the Stock Status to the grid and makes for an easy filter tool. I tried it on 1.7.02 and it worked great.

  • Im still a bit new here. Do I vote up my own answer? Im not OP
    – Dan
    Commented Sep 6, 2013 at 11:39
  • Sorry, not sure what happened, this should have gone with a different question -.- You're answer is good tho so have my upvote! Commented Sep 6, 2013 at 12:28

Since it's a custom module, we need to write a method to filter the stock status in the observer as follows:

public function filterStockStatus($collection, $column)
    $filterValue = $column->getFilter()->getValue();
    )->addFieldToFilter('is_in_stock', array('eq' => $filterValue));

Note: Use the corresponding method name in the addColumn method.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.