0
votes

I'm new to magento and trying to add quantity column to the grid in related products tab (edit product -> related products). this is what I did:

  • overwrite related.php file:
Mage\Adminhtml\Block\Catalog\Product\Edit\Tab\Related.php
  • added to _prepareCollection() method this code:
$collection->joinField(
    'qty',
    'cataloginventory_stock_item',
    'qty',
    'product_id = entity_id',
    '{{table}}.stock_id = 1',
    'left'
);
  • and added to _prepareColumns() methods this code:
$this->addColumn('qty', 
    array(
        'header'    => Mage::helper('catalog')->__('QTY'),
        'width'     => 80,
        'index'     => 'qty'

Now I can see the new column but the quantity is float number (for example 100.00) and I can't filter results based on my new QTY column.

My questions:

  1. is that all I need to add column or I have to do some thing else??
  2. how to display QTY in integer format (for example 100 not 100.00)??
  3. why I can't filter results based on the QTY??

any idea will be appreciated, Thanks in advance..

2
No ideas? .. I can't go to page 2 after adding new column - rramiii

2 Answers

1
votes

Quantity as integer format

'getter'    => array($this, 'getFormattedQty')

public function getFormattedQty($row)
{
   return intVal($row->getQtyOrdered());
}
1
votes

To cover the three questions simply add the 'type' option with the value set to 'number' in the to _prepareColumns() method. Example Below:

    $this->addColumn('qty', array(
        'header'    => Mage::helper('catalog')->__('QTY'),
        'type'      => 'number',
        'width'     => 80,
        'index'     => 'qty'
    ));

This will set the value as a whole number or integer rather than a float and will let you filter for a particular range.

I have used this myself to add the QTY to the Associated Products grid.