Magento-按store_id过滤类别资源集合 [英] Magento - Filter category resource collection by store_id

查看:48
本文介绍了Magento-按store_id过滤类别资源集合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图提取仅属于当前商店的类别,但似乎不起作用.谁能在我的代码中看到任何问题?

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);

那也从store_id 0获取数据,但我只希望从store_id 2获取数据

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)

更新

我没有添加存储过滤器,而是添加了路径过滤器来解决此问题,但仍然希望知道存储过滤器是否有效.

Instead of store filter, I just added path filter which solved the issue but still would love to know if store filter works.

$storeId = Mage::app()->getStore()->getId();
$categoryRootId = Mage::app()->getStore($storeId)->getRootCategoryId();;

$categoryCollection = Mage::getResourceModel('catalog/category_collection')
    ->addFieldToFilter('path', array('like' => "%/{$categoryRootId}/%"))
    ->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','store_id'))
    ->setOrder('position', 'asc')
    ->load();

推荐答案

我知道这是一个老问题,但是如果有人像我一样在寻找答案,

i know it is an old question, but if someone is looking for the answer as i just was:

->addStoreFilter( {storeID} )

是为我做的...

这篇关于Magento-按store_id过滤类别资源集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆