我是magento的新手,并尝试在相关产品标签中添加数量列到网格(编辑产品 - >相关产品) . 这就是我做的:
- overwrite related.php文件:
Mage\Adminhtml\Block\Catalog\Product\Edit\Tab\Related.php
- 添加到
_prepareCollection()
方法此代码:
$collection->joinField(
'qty',
'cataloginventory_stock_item',
'qty',
'product_id = entity_id',
'{{table}}.stock_id = 1',
'left'
);
- 并添加了
to _prepareColumns()
方法此代码:
$this->addColumn('qty',
array(
'header' => Mage::helper('catalog')->__('QTY'),
'width' => 80,
'index' => 'qty'
现在我可以看到新列,但数量是浮点数(例如100.00),我无法根据我的新 QTY
列过滤结果 .
我的问题:
-
是我需要添加列的所有内容还是我必须做其他事情?
-
如何以整数格式显示QTY(例如100不是100.00)?
-
为什么我不能根据QTY过滤结果?
任何想法将不胜感激,在此先感谢..
2 回答
数量为整数格式
要覆盖这三个问题,只需在
_prepareColumns()
方法中添加'type'
选项,并将值设置为'number'
. 示例如下:这会将值设置为整数或整数而不是浮点数,并允许您筛选特定范围 .
我自己用它来将QTY添加到Associated Products网格中 .