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

时间:2016-07-25 08:41:12

标签: php mysql magento magento-1.8

我有这个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'

这将返回除了我从Magento后端创建新类别但未显示的类别之外的所有类别。

该类别已发布且未包含任何产品。 以下图片来自catalog_category_entity_varchar表。

enter image description here

我运行该查询时显示

entity_id = 449,因为它有attribute_id = 57 and 41

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

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

2 个答案:

答案 0 :(得分:1)

只是一个猜测......

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'

答案 1 :(得分:1)

您正在从EAV类别模型中选择具有private void doSalesTotals() { olSales.addListener(new ListChangeListener<Sales>() { @Override public void onChanged(Change<? extends Sales> change) { while (change.next()){ if (change.wasAdded()){ for (Sales s : change.getAddedSubList()){ totalWithDiscount.set(totalWithoutDiscount.get().add(s.getAmount())); System.out.print(totalWithDiscount); } } else if (change.wasRemoved()){ } else if (change.wasReplaced()){ } else if (change.wasUpdated()){ } } } }); 类型5741类型的类别:

varchar

根据我的1.9 magento安装,这是cc.attribute_id = '57' cc1.attribute_id = '41' 的{​​{1}}和name属性:

path

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

catalog/catagory

或获取名称类别使用此:

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