magento 高级目录 产品搜索 按类别过滤
对产品进行高级目录搜索并按类别及其子类别进行过滤的最简单方法是什么?目前我正在搜索产品标题或简短描述或详细描述中找到的关键字。虽然当我不包含任何类别时这确实有效,但我不知道如何在我的产品集合中包含多个类别作为过滤器。
这是我正在更新的一些代码
/**
* Retrieve advanced search product collection
*
* @return Mage_CatalogSearch_Model_Mysql4_Advanced_Collection
*/
public function getProductCollection(){
if (is_null($this->_productCollection)) {
$this->_productCollection = Mage::getResourceModel('catalogsearch/advanced_collection')
->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())
->addMinimalPrice()
->addStoreFilter();
Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($this->_productCollection);
Mage::getSingleton('catalog/product_visibility')->addVisibleInSearchFilterToCollection($this->_productCollection);
/* include category filtering */
/*
if ($category = filter_input(INPUT_GET, 'category', FILTER_VALIDATE_INT)) {
$this->_productCollection->addCategoryFilter(Mage::getModel('catalog/category')->load($category),true);
}
*/
}
return $this->_productCollection;
}
:这正是我想要做的 - 除了我需要搜索任何类别而不是所有类别中的产品, 产品类别搜索
What would be the easiest way to do an advanced catalog search for a product and filter by a category and its sub-categories? currently I'm searching on a keyword found in the products title or short description or long description. While this does work when I don't include any categories, I'm lost how to include multiple categories as a filter in my productCollection.
Here is some of the code I'm working w/
/**
* Retrieve advanced search product collection
*
* @return Mage_CatalogSearch_Model_Mysql4_Advanced_Collection
*/
public function getProductCollection(){
if (is_null($this->_productCollection)) {
$this->_productCollection = Mage::getResourceModel('catalogsearch/advanced_collection')
->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())
->addMinimalPrice()
->addStoreFilter();
Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($this->_productCollection);
Mage::getSingleton('catalog/product_visibility')->addVisibleInSearchFilterToCollection($this->_productCollection);
/* include category filtering */
/*
if ($category = filter_input(INPUT_GET, 'category', FILTER_VALIDATE_INT)) {
$this->_productCollection->addCategoryFilter(Mage::getModel('catalog/category')->load($category),true);
}
*/
}
return $this->_productCollection;
}
UPDATE: this is exactly what I'm trying to do - except I need to to search for products in any of the categories not all the categories, product category search
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论