magento 高级目录 产品搜索 按类别过滤

发布于 2024-10-13 13:45:11 字数 1556 浏览 1 评论 0原文

对产品进行高级目录搜索并按类别及其子类别进行过滤的最简单方法是什么?目前我正在搜索产品标题或简短描述或详细描述中找到的关键字。虽然当我不包含任何类别时这确实有效,但我不知道如何在我的产品集合中包含多个类别作为过滤器。

这是我正在更新的一些代码

    /**
     * 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文