2016-07-25 74 views
1

我有這個SQL查詢來獲取所有Magento類別。使用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 我想純粹的SQL查詢,沒有Magento代碼!

回答

1

您的選擇會從具有屬性57varchar41 EAV的分類模型類:

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

據我1.9的Magento安裝這是namepath屬性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);

要獲得所有原料類使用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') 
+0

我想要一個SQL查詢不是magento代碼 – Umair

+0

我沒有CODE訪問該網站,只有後端訪問.... – Umair

+0

從哪個表?我可以發佈它,如果你告訴我表 – Umair

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' 
+0

它也返回相同數量的結果:(didnt返回類別我缺少 – Umair

相關問題