nzrobert Posted May 3, 2010 Share Posted May 3, 2010 Hi,I have created another category in the back office, and would like to put all products in to that category.Is there a fast was of implementing this through SQL command?CheersRobert Link to comment Share on other sites More sharing options...
rocky Posted May 4, 2010 Share Posted May 4, 2010 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 More sharing options...
nzrobert Posted May 4, 2010 Author Share Posted May 4, 2010 Hi,Thanks heaps for your reply! I got this error: #1046 - No database selected. Link to comment Share on other sites More sharing options...
rocky Posted May 5, 2010 Share Posted May 5, 2010 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 More sharing options...
nzrobert Posted June 1, 2010 Author Share Posted June 1, 2010 Hi Rocky,It worked! thanks man.. Link to comment Share on other sites More sharing options...
nzrobert Posted June 1, 2010 Author Share Posted June 1, 2010 I have just come across something probably a little more difficult i think.I need to copy all products from a particular category to another category.Any ideas? Link to comment Share on other sites More sharing options...
rocky Posted June 1, 2010 Share Posted June 1, 2010 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 More sharing options...
nzrobert Posted June 1, 2010 Author Share Posted June 1, 2010 Im getting a Unknown column 'id_category' in 'where clause' error, would we be looking at the wrong table for clause? Link to comment Share on other sites More sharing options...
rocky Posted June 2, 2010 Share Posted June 2, 2010 You are right. I wrote ps_product when I should've written ps_category_product. I've updated the query above. Link to comment Share on other sites More sharing options...
nzrobert Posted June 5, 2010 Author Share Posted June 5, 2010 works perfect, nice one mate Link to comment Share on other sites More sharing options...
zapmore Posted July 15, 2013 Share Posted July 15, 2013 Is this still valid in version 1.5.4.1? if not, how do I add products from one category to another using SQL in this new version of prestashop? Link to comment Share on other sites More sharing options...
marc.pochet Posted January 5, 2017 Share Posted January 5, 2017 Thank you very much for sharing 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