0
我一直試圖在我的自定義模塊的自定義網格上獲取基於SKU的產品名稱。 我成功地在網格上顯示產品名稱。產品名稱不在Magento中的過濾器搜索的自定義網格中返回
下面是下面的代碼...
<?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();
}
?>
但whernever我試圖篩選搜索的產品名稱它給我下面的錯誤..
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)
我我知道它搜索列名不存在..但我想在哪裏改變...
過濾搜索工作非常細跟所有其他列...