Reputation: 24116
I want to show the stock level at order creation (in backend) during product selection stage in the search grid (Sales_Order_Create_Search_Grid):
How can I go about doing this?
Upvotes: 1
Views: 1042
Reputation: 2483
There are 3 steps.
First: Find this file:
app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Search/Grid.php
And copy it to:
app/code/local/Mage/Adminhtml/Block/Sales/Order/Create/Search/Grid.php
This will help to make sure that you're not overwriting core files and instead creating local versions that won't get affected by upgrades.
Second: In the new file, the _prepareCollection() function will have code like:
$collection = Mage::getModel('catalog/product')->getCollection();
$collection
->setStore($this->getStore())
->addAttributeToSelect($attributes)
->addStoreFilter()
->addAttributeToFilter('type_id', array_keys(
Mage::getConfig()->getNode('adminhtml/sales/order/create/available_product_types')->asArray()
))
->addAttributeToSelect('gift_message_available');
Add this code to that block:
->joinField('qty2',
'cataloginventory/stock_item',
'qty','product_id=entity_id','{{table}}.stock_id=1','left')
So that the finished version looks something like:
$collection = Mage::getModel('catalog/product')->getCollection();
$collection
->setStore($this->getStore())
->addAttributeToSelect($attributes)
->joinField('qty2',
'cataloginventory/stock_item',
'qty','product_id=entity_id','{{table}}.stock_id=1','left')
->addStoreFilter()
->addAttributeToFilter('type_id', array_keys(
Mage::getConfig()->getNode('adminhtml/sales/order/create/available_product_types')->asArray()
))
->addAttributeToSelect('gift_message_available');
Third: Still in the new file, find the _prepareColumns() function and add this code:
$this->addColumn('qty2', array(
'header' => Mage::helper('sales')->__('Stock Level'),
'width' => '20',
'type' => 'number',
'index' => 'qty2'
));
Where you add the above code block into the _prepareColumns() function will determine the order of where the "Stock Level" column will display on the grid.
That's it.
Upvotes: 1