Magento - Filter category resource collection by store_id

Posted by Damodar Bashyal on Stack Overflow See other posts from Stack Overflow or by Damodar Bashyal
Published on 2012-12-07T05:02:32Z Indexed on 2012/12/07 5:03 UTC
Read the original article Hit count: 258

Filed under:

I am trying to pull category that belongs to current store only but it doesn't seem to work. Can anyone see any issue in my code?

$categoryCollection = Mage::getResourceModel('catalog/category_collection')
  ->setStoreId(Mage::app()->getStore()->getId())
  ->addFieldToFilter('include_in_menu', array('eq' => 1))
  ->addFieldToFilter('is_active', array('eq' => 1))
  ->addFieldToFilter('level', array('eq' => 2))
  ->addAttributeToSelect(array('name','url_path','image','description'))
  ->setOrder('position', 'asc');

$categoryCollection->printLogQuery(true);

That's getting data from store_id 0 as well, but i want from only store_id 2

SELECT `e`.*, IF(at_include_in_menu.value_id > 0, at_include_in_menu.value, at_include_in_menu_default.value) AS `include_in_menu`, IF(at_is_active.value_id > 0, at_is_active.value, at_is_active_default.value) AS `is_active` FROM `catalog_category_entity` AS `e`
 INNER JOIN `catalog_category_entity_int` AS `at_include_in_menu_default` ON (`at_include_in_menu_default`.`entity_id` = `e`.`entity_id`) AND (`at_include_in_menu_default`.`attribute_id` = '67') AND `at_include_in_menu_default`.`store_id` = 0
 LEFT JOIN `catalog_category_entity_int` AS `at_include_in_menu` ON (`at_include_in_menu`.`entity_id` = `e`.`entity_id`) AND (`at_include_in_menu`.`attribute_id` = '67') AND (`at_include_in_menu`.`store_id` = 2)
 INNER JOIN `catalog_category_entity_int` AS `at_is_active_default` ON (`at_is_active_default`.`entity_id` = `e`.`entity_id`) AND (`at_is_active_default`.`attribute_id` = '42') AND `at_is_active_default`.`store_id` = 0
 LEFT JOIN `catalog_category_entity_int` AS `at_is_active` ON (`at_is_active`.`entity_id` = `e`.`entity_id`) AND (`at_is_active`.`attribute_id` = '42') AND (`at_is_active`.`store_id` = 2) WHERE (`e`.`entity_type_id` = '3') AND (IF(at_include_in_menu.value_id > 0, at_include_in_menu.value, at_include_in_menu_default.value) = 1) AND (IF(at_is_active.value_id > 0, at_is_active.value, at_is_active_default.value) = 1) AND (`e`.`level` = 2)

© Stack Overflow or respective owner

Related posts about magento