开发者

Adding Stock Status column to Manage Product Admin Page

开发者 https://www.devze.com 2023-03-29 02:16 出处:网络
I\'m trying to add \'stock status\' column开发者_开发知识库 to the Admin Manage Product Grid.

I'm trying to add 'stock status' column开发者_开发知识库 to the Admin Manage Product Grid. Stock status is either "In Stock" or "Out of Stock".

Seems like I need to edit Adminhtml/Block/Catalog/Product/Grid.php 's _prepareColumns().

I added this line

$this->addColumn('stock',
        array(
            'header'=> Mage::helper('catalog')->__('Stock Avail.'),
            'width' => '70px',
            'index' => 'status',
            'type'  => 'options',

            'options' => Mage::getSingleton('cataloginventory/source_stock')->toOptionArray()

which just prints out Array,Array.

I'm guessing it's just printing out the type, so I would need to access the array value to get options. Am I on the right path? I can't find any good coding docs for magento, if anyone can share with me how they figured out magento, that would be really nice.


You should use a renderer: in the array of the addColumn, add:

'renderer' => 'YourNamespace_YourModule_Path_To_Renderer_File',

And the renderer file would be something like:

class YourNamespace_YourModule_Path_To_Renderer_File extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
{
    public function render(Varien_Object $row)
    {
        //let's see what you have to work with
        Zend_Debug::dump($row->getData(), 'debug');

        $stockStatus = $row->getSomething();
        return $stockStatus;
    }
}

Let me know if that ain't clear

0

精彩评论

暂无评论...
验证码 换一张
取 消