Jump to content

[SOLVED] Add all products to a category SQL


Recommended Posts

Try the following SQL query:

INSERT INTO `ps_category_product` SELECT 8, `id_product`, 0 FROM `ps_product`



Change ps_ to your database prefix and change 8 to the ID of the category you want to copy all the products to.

Link to comment
Share on other sites

That's not something caused by the query. Are you executing the query using phpMyAdmin or with code? If you are using phpMyAdmin, make sure that you have clicked on a database before trying to execute the query. If you are using code, you should write:

Db::getInstance()->execute('INSERT INTO `'. _DB_PREFIX_.'category_product` SELECT 8, `id_product`, 0 FROM `'._DB_PREFIX_.'ps_product`);

Link to comment
Share on other sites

  • 4 weeks later...

Try the following:

Db::getInstance()->execute('INSERT INTO `'. _DB_PREFIX_.'category_product` SELECT 8, `id_product`, 0 FROM `'._DB_PREFIX_.'category_product` WHERE `id_category` = 7');



This should copy all the products from category 7 to category 8.

Link to comment
Share on other sites

  • 3 years later...
  • 3 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...