Jump to content

[SOLVED] Add products from specific categories using SQL


Recommended Posts

I have the following scenario:

  • MainCat3
    • All Products within MainCat3
    • SubCat1
    • SubCat2
    • SubCat3
    • etc.

I want to add a link "All products within MainCat3" in the meny, I noticed that a lot of costumers miss that they actually can click "MainCat3".

 

So how would i do to include products from specific categories into another category without going in the each products and attach the category. I was thinking a SQL command or a php code but don't want to try it out blind and break everything....

 

I'm using prestashop v1.5.4.1

 

 

Would something like this work that I found in another old thread:

INSERT INTO `ps_category_product` SELECT 8, `id_product`, 0 FROM `ps_product` WHERE `id_category` = 7 AND  `id_category` = 9 AND  `id_category` = 10

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

I have the following scenario:

  • MainCat3
    • All Products within MainCat3
    • SubCat1
    • SubCat2
    • SubCat3
    • etc.

I want to add a link "All products within MainCat3" in the meny, I noticed that a lot of costumers miss that they actually can click "MainCat3".

 

So how would i do to include products from specific categories into another category without going in the each products and attach the category. I was thinking a SQL command or a php code but don't want to try it out blind and break everything....

 

I'm using prestashop v1.5.4.1

 

 

Would something like this work that I found in another old thread:

INSERT INTO `ps_category_product` SELECT 8, `id_product`, 0 FROM `ps_product` WHERE `id_category` = 7 AND  `id_category` = 9 AND  `id_category` = 10

If you want to add products from either one of the SubCat's you should use the OR switch in the SELECT statement.
Link to comment
Share on other sites

If you want to add products from either one of the SubCat's you should use the OR switch in the SELECT statement.

 

Yes, I want to add all products in these categories. Is these tables correct in Prestashop 1.5.4.1 for what I want to accomplish? I'm afraid to brake the db...

Link to comment
Share on other sites

I used this SQL code but got error message, I thought it was because the category table is called "id_category_default" instead of "id_category" so I changed to the following:

 

INSERT INTO 'ps_category_product' SELECT 44, 'id_product', 0 FROM 'ps_product' WHERE 'id_category_default' = 25 OR 'id_category_default' = 26 OR 'id_category_default' = 27;

 

However I get the following error message:

 

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''ps_category_product' SELECT 44, 'id_product', 0 FROM 'ps_product' WHERE 'id_cat' at line 1

 

What is the problem?

Link to comment
Share on other sites

I used this SQL code but got error message, I thought it was because the category table is called "id_category_default" instead of "id_category" so I changed to the following:

 

INSERT INTO 'ps_category_product' SELECT 44, 'id_product', 0 FROM 'ps_product' WHERE 'id_category_default' = 25 OR 'id_category_default' = 26 OR 'id_category_default' = 27;

 

However I get the following error message:

 

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''ps_category_product' SELECT 44, 'id_product', 0 FROM 'ps_product' WHERE 'id_cat' at line 1

 

What is the problem?

And what was the first error, before you changed the query to id_category_default?
Link to comment
Share on other sites

And what was the first error, before you changed the query to id_category_default?

 

It works now with id_category_default, the problem was that I was using ' instead of `

I always thought ' was the right thing to use.. sorry for your trouble.

Link to comment
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
×
×
  • Create New...