OpenCart: How to accurately populate oc_category_path

后端 未结 1 1902
滥情空心
滥情空心 2021-01-12 03:13

I have used an online service to transfer data from my other ecommerce website into OpenCart and everything seems to have been transferred correctly.

There is howev

1条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-12 04:03

    If a category in your oc store is a root category, it gets an entry in the path table as such "category_id,category_id,0". if that category has a child it will get two entries in the table, namely :-"category_id,category_id,1" as well as "category_id,parent_id,0".

    If that child has a it's own child, that new child will have three entries as such :-
    "category_id,category_id,2"
    "category_id,parent_id,1"
    "category_id,parents parent category_id,0"

    To illustrate this, assume a category has a category_id of "14". It is the first child of a category with a category_id of "11". That category, with the category_id of "11" is the child on a category with the category id of "1". (1>11>14 as show in the admin panel, except with the name instead of the category_id)

    The above will have 3 entries as such :
    "14","14","2"
    "14","11","1"
    "14","1","0"

    So the root category to it will get 0, the next one gets 1, and the next 2, and so forth, all depending on how many category levels down it is.

    I hope that explain things well enough.

    As for populating it, the simplest method, but not a complete method, is to just create the table with "category_id,category_id,0". This will get them to show up in the admin panel. If you then click on "repair" it will generate this table correctly.

    Alternatively you would have to step through you category table, creating an array with it's parent_id, looking up that parent_id for it's parent_id and adding it to the array, and so forth. When the array is complete, ie no more parents, it will be a simple task of adding them to the table with the correct "level".

    FYI, there is another table that needs populating as well, category_to_store, which is very simply "category_id,store_id". Without this table you will not see your categories in your store.

    0 讨论(0)
提交回复
热议问题