简体   繁体   English

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

[英]Product Name not returning in custom grid on filter search in Magento

I have been trying for long to get the product name based on SKU on my custom module's custom grid. 我一直在努力尝试在自定义模块的自定义网格上获取基于SKU的产品名称。 I succeeded in displaying the product name on the grid. 我成功在网格上显示了产品名称。

below is the following code... 以下是以下代码...

 <?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();

        }
    ?>

在此处输入图片说明

But whernever I try to filter search the product name it give me the below error.. 但是无论何时我尝试过滤搜索产品名称,它都会给我以下错误。

  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)

I am aware that it search for the column name which does not exists..but where am I suppose to change... 我知道它搜索不存在的列名..但是我想在哪里更改...

The filter search works very fine with all other columns... 过滤器搜索在所有其他列上都可以正常工作...

just add the follwing code 只需添加以下代码

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM