Magento 2按存储查询获取类别
我想从Magento 2数据库中的查询中获取特定存储的所有启用类别。当我尝试从数据库查询表Magento 2按存储查询获取类别,magento,magento2,Magento,Magento2,我想从Magento 2数据库中的查询中获取特定存储的所有启用类别。当我尝试从数据库查询表catalog\u category\u entity\u int SELECT * FROM `catalog_category_entity_int` WHERE `attribute_id`=46 AND `store_id`=1 GROUP BY `entity_id` 其中,46是启用属性的属性id 通过此查询,我将获得所有类别id,但如果我更改门店id,则所有门店的类别都相同,但所有门店的结果
catalog\u category\u entity\u int
SELECT * FROM `catalog_category_entity_int` WHERE `attribute_id`=46 AND `store_id`=1 GROUP BY `entity_id`
其中,46是启用属性的属性id
通过此查询,我将获得所有类别id,但如果我更改门店id,则所有门店的类别都相同,但所有门店的结果都相同,但我需要特定于门店的类别,正如我在magento admincatalog>Category部分中看到的那样。对当前门店使用\magento\store\Model\StoreManagerface并将其应用于查询中 试试这个
protected $storeManager;
public function __construct(
\Magento\Store\Model\StoreManagerInterface $storeManager,
$data = []
) {
$this->storeManager = $storeManager;
parent::__construct($data);
}
$categoryFactory = $objectManager->create('Magento\Catalog\Model\ResourceModel\Category\CollectionFactory');
$categories = $categoryFactory->create()
->addAttributeToSelect('*')
->setStore($this->storeManager->getStore());
foreach ($categories as $category){
$category->getId();
}
我不是以编程方式从查询中请求的。