[英]Product Name not returning in custom grid on filter search in Magento
我一直在努力嘗試在自定義模塊的自定義網格上獲取基於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();
}
?>
但是無論何時我嘗試過濾搜索產品名稱,它都會給我以下錯誤。
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',
));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.