php - 加入两个表并将结果放入网格 magento 1.9.x

标签 php mysql magento

我正在开发一个自定义模块,其中包含一个包含产品 sku 的平面表格。我想在网格中显示 sku 和从目录/产品中获取的名称以及我自己的表中获取的其他信息; 在 Grid.php 中我有:

 protected function _prepareCollection() 
        {
            $collection = Mage::getModel('hf/hfdistr')->getCollection();

            $this->setCollection($collection);

            return parent::_prepareCollection();
        } 

如何从目录/产品中获取产品名称并将其与我的表格附加信息合并?任何帮助表示赞赏。 (Magento 1.9.3.2)

最佳答案

你可以这样加入他们

$products = Mage::getSingleton('core/resource')->getTableName('catalog/product');
$collection = Mage::getModel('custom/model')->getCollection();
$collection->getSelect()->join(
    array(
      'cp'=> $products
    ),
    'cp.sku = main_table.sku',
    array(
      'cp.sku','cp.other_attribute_other',
      'cp.other_attribute_to_select'
    ));

How to join collections in Magento? 未经测试! :D

关于php - 加入两个表并将结果放入网格 magento 1.9.x,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43520499/

相关文章:

php - 内容在 php 中的 fpdf 单元格中重叠

Php 类型/css 文件无法正常工作

PHP urlencode 和解码

php - "Error establishing a database connection"Wordpress 和谷歌应用引擎

javascript - Express JS 如何与 Google Chart 一起使用

events - Magento Cookie 和数据库在页面加载时工作

php - 使用面向对象表示法的 SolR 查询

PHP Murmurhash3 和 MySql Murmurhash3 有时不匹配

php - Magento 仅显示至少购买过一次的产品

Magento:Mage::getModel ('catalog/category' )->load($id) 不工作