使用 SQL 查询获取所有 Magento 类别

Get all Magento Categories using SQL query

我有这个 SQL 查询来获取所有 Magento 类别。

SELECT DISTINCT
    cc.entity_id AS id,
    cc.`value` AS path,
    cc1.`value` AS `NAME`,
    cce.`level`,
    cce.parent_id
FROM
    catalog_category_entity_varchar cc
JOIN catalog_category_entity_varchar cc1 ON cc.entity_id = cc1.entity_id
JOIN eav_entity_type ee ON cc.entity_type_id = ee.entity_type_id
JOIN catalog_category_entity cce ON cc.entity_id = cce.entity_id
WHERE
    cc.attribute_id = '57'
AND cc1.attribute_id = '41'
AND ee.entity_model = 'catalog/category'

这 returns 所有类别,除了我从 Magento 后端创建一个新类别但未显示的类别。

该类别已发布,其中没有产品。 下图来自 catalog_category_entity_varchar table.

entity_id = 449 在我 运行 查询时显示,因为它有 attribute_id = 57 and 41

但是我说的entity_id = 452是没有显示的,因为它没有attribute_id = 57

想请教Magento专家,attribute_id = 57属于什么?以及如何修复此查询以获取所有类别? PS 我想要纯 SQL 查询,没有 Magento 代码!

只是猜测...

SELECT DISTINCT cc.entity_id id
              , cc.value path
              , cc1.value NAME
              , cce.level
              , cce.parent_id
           FROM catalog_category_entity_varchar cc
           LEFT
           JOIN catalog_category_entity_varchar cc1 
             ON cc.entity_id = cc1.entity_id
            AND cc1.attribute_id = 41
           JOIN eav_entity_type ee 
             ON cc.entity_type_id = ee.entity_type_id
           JOIN catalog_category_entity cce 
             ON cc.entity_id = cce.entity_id
          WHERE cc.attribute_id = 57
            AND ee.entity_model = 'catalog/category'

您正在从具有 varchar 类型的属性 5741 的 EAV 类别模型中选择类别:

cc.attribute_id = '57'
cc1.attribute_id = '41'

根据我的 1.9 magento 安装,这是 catalog/catagorynamepath 属性:

select distinct ea.attribute_code from eav_attribute as ea inner join catalog_category_entity_varchar as vc on ea.attribute_id=vc.attribute_id where vc.attribute_id in (57,41);

要获取所有原始类别,请使用此 sql:

SELECT `e`.* FROM `catalog_category_entity` AS `e` WHERE (`e`.`entity_type_id` = '3')'

或使用名称获取类别:

SELECT `e`.*,
       IF(at_name.value_id > 0, at_name.value, at_name_default.value) AS `name`
FROM `catalog_category_entity` AS `e`
INNER JOIN `catalog_category_entity_varchar` AS `at_name_default` ON (`at_name_default`.`entity_id` = `e`.`entity_id`)
AND (`at_name_default`.`attribute_id` = '41')
LEFT JOIN `catalog_category_entity_varchar` AS `at_name` ON (`at_name`.`entity_id` = `e`.`entity_id`)
AND (`at_name`.`attribute_id` = '41')