0

We are trying to show a column containing the current Quantity on Hand for each product in the "Please Select Products to Add" search grid in the Magento Backend.

I have so far tried to follow two different post's answers:

However get the column, the filtering works, but no QOH is shown, and if we view the source the td only contains a nbsp.

We are using Magento EE 1.13.1.0, so I suppose it's possible that our Grid.php is different than the one in 1.8x or 1.9x CE but it seems doubtful.

Does anyone have any feedback or suggestions on something we might try? I am not sure if I am allowed to paste the source from EE but can if it will help.

Edit:

Here is a screenshot the intended result (albeit broken):

enter image description here

3
  • Not sure, but I am trying to do something similar and getting the same issue. I have cache turned off, and have even tried extending the class rather than just overriding it. Hopefully you find a solution, as I am hoping it will work for me also.
    – user7977
    Commented Jun 4, 2014 at 14:39
  • Do you mean that you want to show current stock in the product grid page? Commented Jun 4, 2014 at 14:48
  • @TBIInfotech Yes, ideally I would like it to show next to the Qty to Add column so that our sales team can see our current stock level when talking to a customer on the phone. The two guides I linked appear to address a simple solution but it appears to only be half working for me on EE. Commented Jun 4, 2014 at 14:55

2 Answers 2

1

It ends up that the code in the other two solutions does work it was a conflict with one of our third party plugins. Sorry to waste everyone's time.

0

Overide block class called

Mage_Adminhtml_Block_Catalog_Product_Grid located in /app/code/core/Mage/Adminhtml/Block/Catalog/Product/Grid.php file.

protected function _prepareCollection()
{
$store = $this->_getStore();
$collection = Mage::getModel('catalog/product')->getCollection()
->addAttributeToSelect('sku')
->addAttributeToSelect('name')
->addAttributeToSelect('short_description') // THIS IS WHAT WE HAVE ADDED
->addAttributeToSelect('attribute_set_id')
->addAttributeToSelect('type_id')
->joinField('qty',
'cataloginventory/stock_item',
'qty',
'product_id=entity_id',
'{{table}}.stock_id=1',
'left');
if ($store->getId()) {
//$collection->setStoreId($store->getId());
$collection->addStoreFilter($store);
$collection->joinAttribute('custom_name', 'catalog_product/name', 'entity_id', null, 'inner', $store->getId());
$collection->joinAttribute('status', 'catalog_product/status', 'entity_id', null, 'inner', $store->getId());
$collection->joinAttribute('visibility', 'catalog_product/visibility', 'entity_id', null, 'inner', $store->getId());
$collection->joinAttribute('price', 'catalog_product/price', 'entity_id', null, 'left', $store->getId());
}
else {
$collection->addAttributeToSelect('price');
$collection->addAttributeToSelect('status');
$collection->addAttributeToSelect('visibility');
}
$this->setCollection($collection);
parent::_prepareCollection();
$this->getCollection()->addWebsiteNamesToResult();
return $this;
}

Add a column

protected function _prepareColumns()
{
$this->addColumn('short Desc',
array(
'header'=> Mage::helper('catalog')->__('Short Desc'),
'index' => 'short_description', //Change your index to qty 
'renderer'  => 'Mage_Adminhtml_Block_Catalog_Product_Renderer_Red',
));
}

Make class

Mage_Adminhtml_Block_Catalog_Product_Renderer_Red extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract


class Mage_Adminhtml_Block_Catalog_Product_Renderer_Red extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
{
public function render(Varien_Object $row)
{
$value =  $row->getData($this->getColumn()->getIndex());
return '<span style="color:red;">'.$value.'</span>';
}
}
1
  • I think we both misunderstood each other, this appears to be for a different grid. I've added a screenshot to clarify. Commented Jun 4, 2014 at 15:20

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.