0

現在のストアのみに属するカテゴリを取得しようとしていますが、うまくいかないようです。誰かが私のコードで何か問題を見ることができますか?

$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 からのみ取得したい

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)

アップデート

ストア フィルターの代わりに、問題を解決するパス フィルターを追加しましたが、ストア フィルターが機能するかどうかを知りたいです。

$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();
4

6 に答える 6

3

私はそれが古い質問であることを知っていますが、誰かが私のように答えを探しているなら:

->addStoreFilter( {storeID} )

私のためにやった...

于 2013-07-04T15:40:26.863 に答える
0

こんにちは、次のコードを確認してください

->addFieldToFilter('store_id', Mage::app()->getStore()->getId());

また

$storeId =Mage::app()->getStore()->getStoreId();

$collection->setStoreId($storeId);

$collection->addStoreFilter($storeId);
于 2012-12-07T05:28:50.657 に答える
0

これを試して

$categoriesCollection = Mage::getModel('catalog/category')
->getCollection()
->setStoreId(1) 
->addFieldToFilter('include_in_menu', array('eq' => 1))
->addFieldToFilter('level', array('eq' => 2))
->addFieldToFilter('is_active', array('eq'=>'1'))
->setOrder('position', 'asc')
->addAttributeToSelect('*');
于 2012-12-07T09:58:09.050 に答える
0

カテゴリテーブルにないため、どちらsetStoreId()も機能しません。以下のコードは完全に機能します。addAttributeToFielter('store_id', $storeId)store_id

$storeId = 21; // your store id
$rootCategoryId = Mage::app()->getStore($storeId)->getRootCategoryId();
$categories = Mage::getModel('catalog/category')->getCollection();
$categories->addAttributeToFilter('path', array('like' => "1/{$rootCategoryId}/%"));
于 2013-11-08T10:54:33.807 に答える