【问题标题】:Adding Stock Status column to Manage Product Grid in Admin在管理员中添加库存状态列以管理产品网格
【发布时间】:2018-06-19 12:12:07
【问题描述】:

我正在尝试将“库存状态”列添加到管理员管理产品网格。库存状态为“有货”或“缺货”。

看来我需要编辑Adminhtml/Block/Catalog/Product/Grid.php

我添加了这一行:

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

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

但只是打印出数组文本....

【问题讨论】:

    标签: magento magento-1.9 stock


    【解决方案1】:

    尝试使用 Mariusthis 答案中提到的以下代码。

    Grid.php 文件中找到 $this->setCollection($collection); 并在此代码之前添加以下代码(加入):

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

    现在您可以添加如下列:

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

    我希望这会有所帮助

    【讨论】:

    • 嗨 Sanchit Gupta,我添加了此代码,但显示错误“属性名称无效:stock_status”。
    • 尝试重新索引并刷新缓存,让我知道它是否有效?
    • 它在我的最后工作正常。请让我检查更多详细信息
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-12
    • 2012-06-14
    相关资源
    最近更新 更多