简体   繁体   English

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

[英]Get all Magento Categories using SQL query

I have this SQL query to get all Magento Categories. 我有此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'

This returns all categories except the one I created a new category from Magento backend but that is not showing. 这将返回所有类别,但我从Magento后端创建了一个新类别的类别除外,但未显示。

That category is published and has no products in it. 该类别已发布,没有任何产品。 Following image is from catalog_category_entity_varchar table. 下图来自catalog_category_entity_varchar表。

在此处输入图片说明

entity_id = 449 is showing when I run that query, because it has attribute_id = 57 and 41 当我运行该查询时,显示entity_id = 449 ,因为它的attribute_id = 57 and 41

But I am talking about entity_id = 452 that is not showing, because it does not have attribute_id = 57 . 但是我说的是没有显示的entity_id = 452 ,因为它没有attribute_id = 57

I want to ask Magento experts, what does attribute_id = 57 belong to? 我想问一下Magento专家, attribute_id = 57属于什么? and how can I fix this query to fetch all categories? 以及如何解决此查询以获取所有类别? PS I want Pure SQL query, No Magento code! PS我要纯SQL查询,没有Magento的代码!

Just a guess... 只是个猜测...

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'

You are selecting categories from EAV category model which has attributes 57 and 41 of varchar type : 您正在从EAV类别模型中选择类别,该模型具有varchar类型的属性5741

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

According to my 1.9 magento installation this are name and path attributes of catalog/catagory : 根据我的1.9 magento安装,这是catalog/catagory类别的namepath属性:

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

To get all raw categories use this sql: 要获取所有原始类别,请使用以下sql:

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

or to get categories with names use this: 或使用名称获取类别,请使用以下命令:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM