如何从目录搜索结果magento中删除所有不属于任何类别的产品

时间:2016-04-19 19:33:18

标签: magento

今天,我尝试从目录搜索结果集合中删除所有不属于任何类别的产品。

在mage \ catalog \ model \ resource \ product \ collection.php我尝试在函数_applyProductLimitations()中添加搜索查询中所有类别ID的列表:

if (!isset($filters['category_ids'])) {
         $conditions[] = $this->getConnection()
            ->quoteInto('cat_index.category_id=?', $filters['category_id']);
        if (isset($filters['category_is_anchor'])) {
            $conditions[] = $this->getConnection()
                ->quoteInto('cat_index.is_parent=?', $filters['category_is_anchor']);
        }
    } else {

        $conditions[] = $this->getConnection()->quoteInto('cat_index.category_id IN(' . implode(',', $filters['category_ids']) . ')', "");
        // $conditions[] = $this->getConnection()->quoteInto('cat_index.category_id = 102');
        // $conditions[] = $this->getConnection()->quoteInto('count(cat_index.category_id) > 0 "" ');
    }

并在catalofsearch图层过滤器模型中添加过滤器:

->addCategoriesFilter($rootCategory->getAllChildren(true))

查询字符串:

SELECT 1 AS `status`, `e`.`entity_id`, `e`.`type_id`, `e`.`attribute_set_id`, `e`.`name`, `e`.`short_description`, `e`.`price`, `e`.`special_price`, `e`.`special_from_date`, `e`.`special_to_date`, `e`.`small_image`, `e`.`thumbnail`, `e`.`news_from_date`, `e`.`news_to_date`, `e`.`url_key`, `e`.`required_options`, `e`.`image_label`, `e`.`small_image_label`, `e`.`thumbnail_label`, `e`.`msrp_enabled`, `e`.`msrp_display_actual_price_type`, `e`.`msrp`, `e`.`tax_class_id`, `e`.`price_type`, `e`.`weight_type`, `e`.`price_view`, `e`.`shipment_type`, `e`.`links_purchased_separately`, `e`.`links_exist`, `e`.`rakuten_top_style`, `e`.`rakuten_top_style_value`, `e`.`gift_type`, `e`.`gift_value`, `e`.`gift_price`, `e`.`gift_from`, `e`.`gift_to`, `e`.`gift_dropdown`, `e`.`gift_price_type`, `cat_index`.`position` AS `cat_index_position`, `tmp_table`.`relevance`, `price_index`.`price`, `price_index`.`tax_class_id`, `price_index`.`final_price`, IF(price_index.tier_price IS NOT NULL, LEAST(price_index.min_price, price_index.tier_price), price_index.min_price) AS `minimal_price`, `price_index`.`min_price`, `price_index`.`max_price`, `price_index`.`tier_price` FROM `catalog_product_flat_1` AS `e` INNER JOIN `catalog_category_product_index` AS `cat_index` ON cat_index.product_id=e.entity_id AND cat_index.store_id='1' AND cat_index.category_id IN(2,102,100,127,32,90,92,94,96,104,84,98,129,112,113,114,115,116,117,118,125,130,131,132,133,135,136,137,138,139,140,141,142,143,33,101,128,35,36,34,43,91,93,95,45,57,63,73,77,107,108,111,124,53,54,55,56,71,72,76,110,97,83,109,78,81,82,85,86,87,88,99) LEFT JOIN `searchindex_result_mage_catalog_product` AS `tmp_table` ON (tmp_table.product_id=e.entity_id) INNER JOIN `catalog_product_index_price` AS `price_index` ON price_index.entity_id = e.entity_id AND price_index.website_id = '1' AND price_index.customer_group_id = 0 WHERE (tmp_table.id IS NOT NULL) ORDER BY `relevance` desc

但搜索结果仍然是不属于任何类别的产品,请给我一些建议怎么做,非常感谢你!

0 个答案:

没有答案