1

What I want to achive is, to show one column in the catalog grid, which contains the stock status.

Here is my code for adding it to the collection that:

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

I also add a new column:

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

The Problem now is that if no stock status is set, there is no entry in the db-table cataloginventory_stock_status. This also means, that products which have no stock status set will not even be displayed in this new catalog grid.

Is there a way to display them anyway?

1
  • instead, try using catalog_inventory_stock_item and test is_in_stock Jul 17, 2014 at 7:35

1 Answer 1

3

That happens because, by default joinTable performs an INNER JOIN. You can pass an additional parameter to make a LEFT JOIN.

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

Your Answer

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

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