1

我正在尝试根据 store_id 获取类别列表,但我所有的尝试都失败了

我试过了

$categories = Mage::getModel('catalog/category')
                ->getCollection()
                ->setStoreId(21)
                ->addAttributeToSelect('*');

但它给了我所有商店的所有类别,我试过了

->addFieldToFilter('store_id', '21')

和 ->addStoreFilter(21)

但没有运气,任何帮助或建议将不胜感激,在此先感谢您

4

4 回答 4

4

magento 中的类别不必存储关系(因为它被商店使用(例如,商店可以指向子类别作为其根类别)等。)因此,您创建的任何类别都将在所有商店中可见。

但是 is 具有属性 is_active (这是商店视图范围)。

因此,要获取特定商店中的类别(您需要确保其在其他商店中不活跃)

并使用属性过滤

->addFieldToFilter('is_active', 1)

希望这对您有所帮助。

于 2013-05-24T21:02:11.930 回答
2

这适用于 1.9

$storeId = Mage::app()->getStore()->getStoreId();
$rootCategoryId = Mage::app()->getStore($storeId)->getRootCategoryId();
$categories = Mage::getModel('catalog/category')
->getCollection()
->setStoreId($storeId)
->addFieldToFilter('is_active', 1)
->addAttributeToFilter('path', array('like' => "1/{$rootCategoryId}/%"))
->addAttributeToSelect('*');
于 2014-09-24T15:30:04.510 回答
1

尝试这个:

$storeId = 21;
$rootCategoryId = Mage::app()->getStore($storeId)->getRootCategoryId();
$categories = Mage::getModel('catalog/category')->getCollection();
$categories->addAttributeToFilter('path', array('like' => "1/{$rootCategoryId}/%"));
于 2013-11-08T10:50:12.613 回答
-1
$storeId=21;
->addFieldToFilter('store_id',$storeId)
于 2013-05-26T04:55:31.763 回答