immc Posted Friday at 05:18 AM Share Posted Friday at 05:18 AM I'm in the build & break stage of learning PrestaShop ver8.2 and have a working understanding of the type of category hierarchy I need for this project. The problem is the amount of time it takes to create these categories. How to Export Categories & Sub-categories If I click Categories > Export I get a spreadsheet containing Name, Description, Position, Displayed of the 7 categories but not any of the sub-categories nested in each. I came across this query statement: SELECT * FROM tsf_category, tsf_category_lang WHERE tsf_category.id_category = tsf_category_lang.id_category; I changed the table prefix, select the category table from the list of MySQL Tables and try to save the new SQL query but an unexpected error is thrown. Anyone have this process documented and tested on ver 8.2? I need this .csv available to import into rebuilds. Any responses appreciated. Link to comment Share on other sites More sharing options...
musicmaster Posted Friday at 11:54 AM Share Posted Friday at 11:54 AM Your post is long but hard to understand. The ps_category table contains everything you need about its position in the hierarchy. The most important field is id_parent that points to the id_category of the parent category. Position gives the relative position versus its peers. Level_depth is strictly spoken not needed. is_root signals that the category is the root of some shop. It is not the absolute root of the category tree: there is one level below that has as id_parent a zero. Note that in shops that originate from before version 1.5 - when Prestashop introduced multishop - this lowest level will have a relatively high id_category. The field nleft and nright are also related to the position of the categories towards each other. But that belongs in the advanced studies department. Link to comment Share on other sites More sharing options...
Knowband Plugins Posted Friday at 12:10 PM Share Posted Friday at 12:10 PM On 3/21/2025 at 5:18 AM, immc said: SELECT * FROM tsf_category, tsf_category_lang WHERE tsf_category.id_category = tsf_category_lang.id_category; Expand Whats your query here? What an unexpected error. The query seems fine if having sing language on the store. Link to comment Share on other sites More sharing options...
immc Posted Friday at 11:34 PM Author Share Posted Friday at 11:34 PM Apologies, but as stated I'm new to self-hosting PrestaShop ver8.2 and trying to figure out the actual process to successfully export the 132 categories I've created to a spreadsheet. These are nested inside of seven (7) categories: category_1 - sub_cat_1 - sub_cat_2 category_2 - sub_cat_1 - sub_cat_2 category_3 - sub_cat_1 - sub_cat_2 etc... Based on what I've discovered thus far I'm suppose to click Categories > Gear icon > Export to perform the export but it doesn't include the 132 categories I've created. What I get in this export are the seven (7) categories but not the sub-categories nested under them. The documentation doesn't go into detail on this process: https://docs.prestashop-project.org/v.8-documentation/user-guide/selling/managing-catalog/managing-categories#managingcategories-importingandexportingcategories I came across this query while searching other forum threads: Thread: Query: SELECT * FROM ps_category, ps_category_lang WHERE ps_category.id_category = ps_category_lang.id_category; Pasting this into SQL query returns the following error: The "ps_category" table does not exist. I modify this query by changing the ps_ prefix, which I changed when installing PrestaShop, to tsf_. So: SELECT * FROM tsf_category, tsf_category_lang WHERE tsf_category.id_category = tsf_category_lang.id_category; I go to Advanced Parameters > Database which opens SQL Manager. - Click Add new SQL query. - Enter name for query. - Paste in query: SELECT * FROM tsf_category, ps_category_lang WHERE tsf_category.id_category = tsf_category_lang.id_category; - Click Save. Error: Oops... looks like an unexpected error occurred. Click back to returns error: I enable debug and get the following error after attempting to run the query: Bad SQL Query. I see List of MySQL Tables and can confirm that every table leads with tsf_ as opposed to ps_. Again, I'm simply trying to figure out and document the process for future exports. Any assistance is appreciated. Link to comment Share on other sites More sharing options...
Knowband Plugins Posted Saturday at 05:01 AM Share Posted Saturday at 05:01 AM I have tried running the query at my end & it's working fine. If your tables have a prefix i.e. tsf_, both tables should have the same prefix. It seems you are still using ps_category_lang. SELECT * FROM tsf_category, tsf_category_lang WHERE tsf_category.id_category = tsf_category_lang.id_category; Link to comment Share on other sites More sharing options...
Mediacom87 Posted Sunday at 09:18 AM Share Posted Sunday at 09:18 AM Hi, SELECT c.id_category, c.id_parent, cl.name AS category_name, CONCAT_WS(' > ', cl_root.name, cl_lvl1.name, cl_lvl2.name, cl.name ) AS full_path, CASE WHEN c.id_parent = 2 THEN 1 WHEN c_lvl1.id_parent = 2 THEN 2 WHEN c_lvl2.id_parent = 2 THEN 3 ELSE 0 END AS niveau, c.active, c.date_add, c.date_upd FROM ps_category c -- Main category language JOIN ps_category_lang cl ON cl.id_category = c.id_category AND cl.id_lang = 1 -- Joint level 1 (parent) LEFT JOIN ps_category c_lvl1 ON c_lvl1.id_category = c.id_parent LEFT JOIN ps_category_lang cl_lvl1 ON cl_lvl1.id_category = c_lvl1.id_category AND cl_lvl1.id_lang = 1 -- Joint level 2 (grandparent) LEFT JOIN ps_category c_lvl2 ON c_lvl2.id_category = c_lvl1.id_parent LEFT JOIN ps_category_lang cl_lvl2 ON cl_lvl2.id_category = c_lvl2.id_category AND cl_lvl2.id_lang = 1 -- Level 3 join (real root, usually “Home”) LEFT JOIN ps_category_lang cl_root ON cl_root.id_category = 2 AND cl_root.id_lang = 1 WHERE c.id_category NOT IN (1, 2) -- Exclude root and Home if you want ORDER BY full_path; Export : 1. Execute this query in phpMyAdmin, click on “Export” > “CSV”. 2. Open in Excel: you'll get the full_path column, perfect for visually retrieving the structure. Link to comment Share on other sites More sharing options...
immc Posted 5 hours ago Author Share Posted 5 hours ago @Knowband Plugins If I copy and paste this query as is into Advanced Parameters > Database > SQL Manager and click Save it I get an error: SELECT * FROM tsf_category, tsf_category_lang WHERE tsf_category.id_category = tsf_category_lang.id_category; Error: Argument #1 ($string) must be of type string, array given [TypeError 0] Adding this into a SQL validator doesn't return an issue with the statement. @Mediacom87 After changing the prefix from ps_ to tsf_ I was able to use this export the csv via phpMyAdmin. Thanks! The ideal scenario would be to use the Prestashop sample csv to import this data into a staging environment, make changes, and then import that updated csv back into the Prestashop live site. I unfortunately can't make sense of the format in this Prestashop sample categories csv versus the csv exported from phpMyAdmin. Link to comment Share on other sites More sharing options...
immc Posted 2 hours ago Author Share Posted 2 hours ago Just noticed that if I click Categories > Gear > Export and then attempt to import the few categories that are exported into my stage site the meta data isn't included and the category title is wrong. So I basically have to manually enter every category. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now