php - Magento 中过滤器搜索时的自定义网格中未返回产品名称

标签 php mysql magento zend-framework

我长期以来一直在尝试根据自定义模块的自定义网格上的 SKU 获取产品名称。 我成功在网格上显示了产品名称。

下面是以下代码...

 <?php
    protected function _prepareCollection()
        {
            $collection = Mage::getModel('questionanswer/answer')->getCollection();
            // $collection_join = Mage::getModel('questionanswer/answer')->getCollection()
            //     ->join(
            //         'questionanswer/question',
            //         '`questionanswer/question`.question_id=`main_table`.question_id'
            //         ,array('question')
            //         )
            //          ->join(
            //         'catalog/product',
            //         '`catalog/product`.entity_id=`main_table`.product_id'
            //         ,array('sku')
            //         );
    
            $entityTypeId = Mage::getModel('eav/entity')
              ->setType('catalog_product')
              ->getTypeId();
            $prodNameAttrId = Mage::getModel('eav/entity_attribute')
              ->loadByCode($entityTypeId, 'name')
              ->getAttributeId();
            $collection->getSelect()
              ->joinLeft(
            array('prod' => 'catalog_product_entity'), 
            'prod.entity_id = main_table.product_id',
            array('sku')
            )
            ->joinLeft(
            array('cpev' => 'catalog_product_entity_varchar'), 
            'cpev.entity_id=prod.entity_id AND cpev.attribute_id='.$prodNameAttrId.'', 
            array('name' => 'value')
            )->joinLeft(
            array('que'=>'questionanswer_question'),
            'que.question_id = main_table.question_id',
            array('question')
            ); 
                
                $this->setCollection($collection);
            return parent::_prepareCollection();
            
        }
    ?>

enter image description here

但是每当我尝试过滤搜索产品名称时,都会出现以下错误..

  a:5:{i:0;s:413:"SQLSTATE[42S22]: Column not found: 1054 Unknown column 'name' in 'where clause', query was: SELECT COUNT(*) FROM `questionanswer_question` AS `main_table`
 LEFT JOIN `catalog_product_entity` AS `prod` ON prod.entity_id = main_table.product_id
 LEFT JOIN `catalog_product_entity_varchar` AS `cpev` ON cpev.entity_id=prod.entity_id AND cpev.attribute_id=71 WHERE (`name` LIKE '%hp%') AND (`status` LIKE '%pending%')";i:1;s:6069:"#0 /home/vhost/_default/magento1.9.2/lib/Varien/Db/Statement/Pdo/Mysql.php(110): Zend_Db_Statement_Pdo->_execute(Array)
#1 /home/vhost/_default/magento1.9.2/app/code/core/Zend/Db/Statement.php(291): Varien_Db_Statement_Pdo_Mysql->_execute(Array)

我知道它搜索不存在的列名..但是我应该在哪里更改...

过滤器搜索与所有其他列配合得很好...

最佳答案

只需添加以下代码

 $this->addColumn('names',array(
                          'header' => 'Product Name',
                          'index' => 'name',
                          'filter_index'=> 'value',
          ));

关于php - Magento 中过滤器搜索时的自定义网格中未返回产品名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36259466/

相关文章:

php - 如何使用 GET 或 POST 方法将变量传递到 php 中的另一个页面?

php - 如何在 while 循环中从 mysqli_fetch_array() 检索当前和下一个元素?

php - 覆盖多个模块中的 magento block (以及如何忽略其他模块)

mysql - 如何使用分组依据更新查询

php - 有人可以解释这段 magento 代码吗?

Magento 更改单页结账页面标题

php - 列数与第 1 行的值数不匹配

php - mysqli_real_escape_string 出现解析错误

php - 在 PHP 中的动态页面上搜索

php - 在 PHP 中下载 URL 的内容,即使它返回 404