Jump to content

Export csv of all the categories


marie12

Recommended Posts

Hello,
I need to export all the categories, included their name and link_rexrite.
 

I tried the solution given here :

SELECT
a.`id_category`, `active`, `name`, a.`id_parent`, a.`is_root_category`, `description`, `meta_title`, `meta_description`, a.`id_shop_default`
FROM `ps_category` a 
LEFT JOIN `ps_category_lang` b ON (b.`id_category` = a.`id_category` AND b.`id_lang` = 5 AND b.`id_shop` = 5)
LEFT JOIN `ps_category_shop` sa ON (a.`id_category` = sa.`id_category` AND sa.id_shop = 5)  
WHERE 1


ORDER BY a.`id_category` ASC

But infortunately, some columns are empty : active, name, description... all the values without the alias "a.".

But this is specially the ones I need !

 

I tried to rewrite this code to obtain the data in my csv files.

Il tried to write :

FROM `ps_category_lang` a

because it's in this table we find the data I need (and I changed some other things in this code...)

I tried to use UNION to have data from the 2 tables `ps_category_lang` and `ps_category`

...but without success...

because I'm not an SQL expert...

 

I need the list of all the categories with the name, the id and the link_rewrite, to delete many of them, create some new one, and re-organize the tree of categories.

 

So somenone can help to complete this code (that is an interesting code for beginning).

 

Regards

Edited by marie12 (see edit history)
Link to comment
Share on other sites

The SQL looks correct, the field without the "a." are retrieved from the "ps_category_lang" table. From your problem it seems like what is wrong is the language id and/or shop id in:

AND b.`id_lang` = 5 AND b.`id_shop` = 5

and:

= sa.`id_category` AND sa.id_shop = 5

Are you sure 5 is the correct id for the language and the shop? If you are using default single-shop installation, the shop id should be 1. You can check the language id in Localization > Languages, id column. 

 

Let us know if you manage to get the correct result. 

  • Thanks 2
Link to comment
Share on other sites

Tank you for the reply.

 

Your were right :

I found the number of the shop, not in the back-office, but in the database, and it was 1.

For the language, it was 2.

 

So the request is now :

SELECT
a.`id_category`, `active`, `name`, a.`id_parent`, a.`is_root_category`, `description`, `link_rewrite`, `meta_title`, `meta_description`, a.`id_shop_default`
FROM `ps_category` a
LEFT JOIN `ps_category_lang` b ON (b.`id_category` = a.`id_category` AND b.`id_lang` = 2 AND b.`id_shop` = 1)
LEFT JOIN `ps_category_shop` sa ON (a.`id_category` = sa.`id_category` AND sa.id_shop = 1)  
WHERE 1


ORDER BY a.`id_category` ASC

And it works, it gives me exactly that I need. All the columns are filled.

Thank you for the help !

  • Like 1
Link to comment
Share on other sites

  • 6 years later...

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...