如何在产品网格中添加自定义SQL调用。
这就是我目前所拥有的:
$collection = Mage::getModel('catalog/product')->getCollection()
->addAttributeToSelect('sku')
->addAttributeToSelect('name')
->addAttributeToSelect('attribute_set_id')
->addAttributeToSelect('type_id');
$collection->joinField(
'quantity_in_stock',
'advancedinventory',
'quantity_in_stock',
'product_id=entity_id',
'advancedinventory.place_id=1',
'inner'
);
$this->addColumn('quantity_in_stock',
array(
'header'=> Mage::helper('catalog')->__('Custom Column'),
'width' => '80px',
'type' => 'number',
'index' => 'quantity_in_stock'
));
但这似乎不起作用,我需要从表
advancedinventory
中获取值,其中product_id
是实体的id,place_id
始终等于1。有人能帮忙吗?
最佳答案
解决了,
为了解决这个问题,我不得不将这个集合设为:
$collection = Mage::getModel('catalog/product')->getCollection()
->addAttributeToSelect('sku')
->addAttributeToSelect('name')
->addAttributeToSelect('attribute_set_id')
->addAttributeToSelect('type_id')
->joinField('quantity_in_stock', 'mage_advancedinventory', 'quantity_in_stock', 'product_id=entity_id', 'place_id=1', 'left');`
$this->addColumn('quantity_in_stock',
array(
'header'=> Mage::helper('catalog')->__('Custom Column'),
'width' => '80px',
'type' => 'number',
'index' => 'quantity_in_stock'
)
);