[英]Magento: How to search for products in category by name in mini search
我想在Magento的迷你搜索表單中搜索類別。
但不是帶有類別列表的下拉菜單。 當我在小型搜索表單中輸入類別的名稱時,它應該顯示該類別之外的產品。
例:
我搜索“套頭衫”,即使搜索字符串(“套頭衫”)與標題和說明不匹配,結果也應包括所有帶有套頭衫的產品,並且所有與常規搜索過濾器匹配且不在類別套頭衫中
我覺得我有掛接到方法prepareResult()
中的Mage_CatalogSearch_Model_Resource_Fulltext
有一個塊,其中定義了$ select對象:
$select = $adapter->select()
->from(array($mainTableAlias => $this->getMainTable()), $fields)
->joinInner(array('e' => $this->getTable('catalog/product')),
'e.entity_id = s.product_id',
array())
->where($mainTableAlias.'.store_id = ?', (int)$query->getStoreId());
有人知道我也可以搜索類別嗎?
這是正確的方法嗎?
我做了很多努力才意識到這一點。 這是我的問題的第一個“ hacky”解決方案:
我重寫了Mage_CatalogSearch_Model_Resource_Fulltext->_prepareProductIndex()
在測試in_stock和退貨之間,我插入了類似以下內容:
$query = "
SELECT `cv`.`value`
FROM `catalog_category_entity_varchar` AS `cv`
LEFT JOIN `catalog_category_product` AS `ccp`
ON (`ccp`.`category_id` = `cv`.`entity_id`)
WHERE `ccp`.`product_id` = " . $this->_getReadAdapter()->quote($productData['entity_id']) . "
AND `cv`.`store_id` = " . $this->_getReadAdapter()->quote($queryStoreId) . "
AND `cv`.`attribute_id` = (
SELECT `attribute_id` FROM `eav_attribute` WHERE `attribute_code` = 'name' AND `entity_type_id` = 3
);
";
$categories = array();
foreach ($this->_getReadAdapter()->fetchAll($query) as $result)
$categories[] = html_entity_decode($result['value']); // HACK!!!
$index['categories'] = $categories;
下一步是將其放入幫助函數並抽象表名稱。
也許會有人發現這有幫助:-)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.