Jump to content

[SOLVED] Prestashop query MYSQL for category


ietax
 Share

Recommended Posts

I need correct query for export parent category on prestashop.


On Prestashop there are 2 tables.


ps_category_lang - id_category - name


ps_category - id_category - id_parent


id_parent is category number of upper category i'd like to associate name of upper category to correct id_parent.


I hope to be clear. thanks.


Edited by ietax (see edit history)

Share this post


Link to post
Share on other sites

Ok, i will try

 

SELECT ps_category.id_category, ps_category_lang.name, ps_category.id_parent FROM ps_category LEFT JOIN ps_category_lang ON (ps_category.id_category = ps_category_lang.id_category) WHERE ps_category_lang.id_lang = 3

 

 

 

id_category     name           id_parent      
1                      Root                      0                  
2                       Home                   1           

 

i'd like to have one more column with name ok id_parent 

 

es. 

 

id_category     name           id_parent           name_parent
1                      Root                      0                  
2                       Home                   1                      Root
Edited by ietax (see edit history)

Share this post


Link to post
Share on other sites

Here we go:

SELECT c.id_category, c.id_parent, cl.name cat_name, clp.name parent_name
FROM ps_category c
LEFT JOIN ps_category_lang cl    ON cl.id_category = c.id_category AND cl.id_lang = 1
LEFT JOIN ps_category cp         ON cp.id_category = c.id_parent
LEFT JOIN ps_category_lang clp    ON clp.id_category = cp.id_category AND clp.id_lang = 1

If you use more than one language, you can use id_lang = 1 (where 1 is your desired language id) to limit to one language only.

You can delete these conditions and you'll get the output for all languages.

Share this post


Link to post
Share on other sites

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
 Share

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More