如何在产品网格中添加自定义 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'
)
);
关于php - 产品网格中的自定义 SQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24486672/