php - 产品网格中的自定义 SQL

标签 php sql magento zend-framework2 magento-1.9

如何在产品网格中添加自定义 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/

相关文章:

php - 如何从 PHP 脚本与 python 守护进程通信

sql - 如何在 SSRS 中实现 'Not In' 过滤器?

php - Magento 重新索引单个项目和相关组产品的正确方法

MySQL 查询 3 表内部连接只返回 1 行

php - 使用文本区域发布数据是否会自动添加斜杠(转义)文本?

php - 重定向返回后如何保留已输入的值

php - 当 url 中使用连字符 (-) 时,Htaccess 不起作用

java - Android - 与 SQL 查询作斗争

mysql - 从两个不同的表中选择数据

magento 对自定义集合进行分页