2010-09-08 97 views
3

場景: 一個新的空白Magento,帶有一些類別產品和客戶導入,並帶有一些修復程序。將Magento類別複製到父母

分類結構:

Root 
L..Category_parent1 (0 products) 
    L..Category_child1 (22) 
    L..Category_child2 (34) 
L..Category_parent2 (0) 
    L..Category_child1 (22) 
    L..Category_child2 (34) 
L..Category_parent3 (0) 
    L..Category_child1 (22) 
    L..Category_child2 (0) 
     L..Category_child2_child1 (22) 
     L..Category_child2_child2 (34) 
    L..Category_child3 (10) 

我想將所有產品從使用SQL查詢或PHP腳本子類別的相對父。 (我不知道是否可以通過Magento管理員執行此操作)。

所需的結果:

Root 
L..Category_parent1 (22 + 34 products) 
    L..Category_child1 (22) 
    L..Category_child2 (34) 
L..Category_parent2 (22 + 34) 
    L..Category_child1 (22) 
    L..Category_child2 (34) 
L..Category_parent3 (22 + 22 + 34 + 10) 
    L..Category_child1 (22) 
    L..Category_child2 (22 + 34) 
     L..Category_child2_child1 (22) 
     L..Category_child2_child2 (34) 
    L..Category_child3 (10) 

更新! 有沒有辦法只在展示產品上做到這一點? 以這種方式查看產品manteining relashionship與他們自己的類別(只需在列表中查看佈局...)?

回答

2

由於部分解決方案:

insert into catalog_category_product_index (
    select cat.parent_id, prod.product_id, 1 
     from catalog_category_product_index prod, catalog_category_entity cat 
     where prod.category_id = cat.entity_id and cat.level >= 1 
); 

這應該選擇一切,撞它的水平(直到我們得到根)。單獨的查詢將有助於位置列(當前硬編碼爲1)。但是,最大的問題是,你的期望結果實際上會使物品碰到多於一個等級,而這個查詢只能達到一個等級。爲了真正地推廣,可以將這個查詢放到一些代碼中,並從最低深度​​開始並向上移動。

希望有幫助!

謝謝, 喬

+0

的作品,但我認爲這是更好地做到這一點的查看模式(出於某些實際原因:將所有產品(放置類別)移動到一個類別中,而不必考慮它放在哪裏的產品) – 2010-09-09 00:27:06

1

似乎is_anchor設立於所有類別的解決我的問題,而是由約瑟夫提供的答案回答問題