How to remove all products that are not in any category from catalog search result magento -
today i'm trying remove product not in category catalog search result collection.
in mage\catalog\model\resource\product\collection.php tried add list of categories ids in search query in function _applyproductlimitations():
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 "" '); }
and add filter in catalofsearch layer filter model:
->addcategoriesfilter($rootcategory->getallchildren(true))
query string:
select 1 `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` `cat_index_position`, `tmp_table`.`relevance`, `price_index`.`price`, `price_index`.`tax_class_id`, `price_index`.`final_price`, if(price_index.tier_price not null, least(price_index.min_price, price_index.tier_price), price_index.min_price) `minimal_price`, `price_index`.`min_price`, `price_index`.`max_price`, `price_index`.`tier_price` `catalog_product_flat_1` `e` inner join `catalog_category_product_index` `cat_index` on cat_index.product_id=e.entity_id , cat_index.store_id='1' , 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` `tmp_table` on (tmp_table.product_id=e.entity_id) inner join `catalog_product_index_price` `price_index` on price_index.entity_id = e.entity_id , price_index.website_id = '1' , price_index.customer_group_id = 0 (tmp_table.id not null) order `relevance` desc
but search result still got products not belong category, please give me advice how it, thank much!
Comments
Post a Comment