garywright Posted November 20, 2012 Share Posted November 20, 2012 I have installed PrestaShop 1.5.2.0 and am in the middle of adding new categories via CSV import. However I have noticed that a customer group that I have setup earlier does not have access to the new categories by default, resulting in me having to edit each category manually to add this group via the check box at the bottom of the page. Is there a way that my installation will allow all groups (default or ones I have created) to be able to see all categories? My installation will have over 1000 categories / sub categories and it seems like a very time consuming job if I have to do this manually. Thanks, Gary Link to comment Share on other sites More sharing options...
cryogenn Posted May 11, 2013 Share Posted May 11, 2013 I have installed PrestaShop 1.5.2.0 and am in the middle of adding new categories via CSV import. However I have noticed that a customer group that I have setup earlier does not have access to the new categories by default, resulting in me having to edit each category manually to add this group via the check box at the bottom of the page. Is there a way that my installation will allow all groups (default or ones I have created) to be able to see all categories? My installation will have over 1000 categories / sub categories and it seems like a very time consuming job if I have to do this manually. Thanks, Gary Hello Gary, I was wondering if you found a solution to this problem? Link to comment Share on other sites More sharing options...
hectorgomis Posted October 17, 2013 Share Posted October 17, 2013 I have this problema as well. Anyone found a solution? Thanks 1 Link to comment Share on other sites More sharing options...
femo Posted October 20, 2013 Share Posted October 20, 2013 Me too! Link to comment Share on other sites More sharing options...
Randaal Posted November 8, 2013 Share Posted November 8, 2013 same here Link to comment Share on other sites More sharing options...
Y Talansky Posted March 28, 2014 Share Posted March 28, 2014 (edited) need to add with sql to table ps_category_group for id_category add id_group you can use this script to and then access in your browser see below <?php require(dirname(__FILE__).'/config/config.inc.php'); if ($_SERVER["REQUEST_METHOD"] == "POST") { $new_group = $_POST["new_group"]; $categories = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' SELECT DISTINCT c.* FROM `'._DB_PREFIX_.'category` c LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (c.`id_category` = cl.`id_category` AND cl.`id_lang` = '.(int)Context::getContext()->language->id.') '); foreach($categories as $category){ $categoryObj = new Category($category['id_category'], (int)Context::getContext()->language->id); $categoryObj->addGroups(array($new_group)); } echo 'Updated'; } else { echo' <form method="post" action="'.$_SERVER["PHP_SELF"].'"> Enter New Group id: <input type="text" name="new_group"> <input type="submit" name="update" > </form>'; } ?> Edited March 30, 2014 by Y Talansky (see edit history) 3 Link to comment Share on other sites More sharing options...
vkmaxx Posted November 6, 2015 Share Posted November 6, 2015 Excellent script, works in 1.6.1.1! Link to comment Share on other sites More sharing options...
Alex Nitu Posted November 18, 2015 Share Posted November 18, 2015 Hi, I don't quite understand what I'm suposed to do with that script and what to query inside mysql, can anyone help me? Link to comment Share on other sites More sharing options...
amoswright Posted May 31, 2016 Share Posted May 31, 2016 (edited) I needed a sledgehammer approach: add all groups to all categories. I'm new to PrestaShop, so, can't vouch for my code, but, based upon the suggestion above, came up with a script that simply adds all groups to all categories. You save this code as a new page in your PrestaShop site root folder, then load the page in a browser: <?php require(dirname(__FILE__).'/config/config.inc.php'); $groups= Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' SELECT DISTINCT c.* FROM `'._DB_PREFIX_.'group` c '); $categories = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' SELECT DISTINCT c.* FROM `'._DB_PREFIX_.'category` c LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (c.`id_category` = cl.`id_category` AND cl.`id_lang` = '.(int)Context::getContext()->language->id.') '); foreach($groups as $group){ foreach($categories as $category){ $exists = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('select id_category, id_group from ps_category_group where id_category = "'.$category['id_category'].'" and id_group = "'.$group['id_group'].'"'); if(!$exists) { $categoryObj = new Category($category['id_category'], (int)Context::getContext()->language->id); echo $categoryObj->addGroups(array($group['id_group'])); echo $group['id_group']." added to ".$category['id_category']."<br />"; }else{ echo $group['id_group']." ALREADY added to ".$category['id_category']."<br />"; } } } Edited June 8, 2016 by amoswright (see edit history) 1 1 Link to comment Share on other sites More sharing options...
rejlafond Posted August 3, 2016 Share Posted August 3, 2016 Tested it on 1.6.1.4 and it works great. Thank you amoswright Link to comment Share on other sites More sharing options...
Mejaro Posted October 17, 2016 Share Posted October 17, 2016 THANK YOUUUU!!!!! It works Great! PS 1.6.1.7 Link to comment Share on other sites More sharing options...
Fred Fournier Posted January 27, 2017 Share Posted January 27, 2017 (edited) I needed a sledgehammer approach: add all groups to all categories. I'm new to PrestaShop, so, can't vouch for my code, but, based upon the suggestion above, came up with a script that simply adds all groups to all categories. You save this code as a new page in your PrestaShop site root folder, then load the page in a browser: <?php require(dirname(__FILE__).'/config/config.inc.php'); $groups= Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' SELECT DISTINCT c.* FROM `'._DB_PREFIX_.'group` c '); $categories = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' SELECT DISTINCT c.* FROM `'._DB_PREFIX_.'category` c LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (c.`id_category` = cl.`id_category` AND cl.`id_lang` = '.(int)Context::getContext()->language->id.') '); foreach($groups as $group){ foreach($categories as $category){ $exists = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('select id_category, id_group from ps_category_group where id_category = "'.$category['id_category'].'" and id_group = "'.$group['id_group'].'"'); if(!$exists) { $categoryObj = new Category($category['id_category'], (int)Context::getContext()->language->id); echo $categoryObj->addGroups(array($group['id_group'])); echo $group['id_group']." added to ".$category['id_category']."<br />"; }else{ echo $group['id_group']." ALREADY added to ".$category['id_category']."<br />"; } } } It worked. Thank you so much! Prestashop 1.6.0.9 Edited January 27, 2017 by Fred Fournier (see edit history) Link to comment Share on other sites More sharing options...
jalokin80 Posted January 31, 2017 Share Posted January 31, 2017 (edited) Hi. Thanks for the script. I cannot get it to work on Prestashop 1.6.1.11. Any suggestions appreciated! EDIT: Okay, I managed to get it to work. It was caused by virtual url addresses in a multistore inviroment. I was trying to execute the script from http://main-address.com/allgroups.php but I just needed to include the virtual domain like http://main-domain.com/virtual-domain/allgroups.php and it worked like a charm Edited January 31, 2017 by jalokin80 (see edit history) Link to comment Share on other sites More sharing options...
Isady Posted March 15, 2017 Share Posted March 15, 2017 I needed a sledgehammer approach: add all groups to all categories. I'm new to PrestaShop, so, can't vouch for my code, but, based upon the suggestion above, came up with a script that simply adds all groups to all categories. You save this code as a new page in your PrestaShop site root folder, then load the page in a browser: <?php require(dirname(__FILE__).'/config/config.inc.php'); $groups= Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' SELECT DISTINCT c.* FROM `'._DB_PREFIX_.'group` c '); $categories = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' SELECT DISTINCT c.* FROM `'._DB_PREFIX_.'category` c LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (c.`id_category` = cl.`id_category` AND cl.`id_lang` = '.(int)Context::getContext()->language->id.') '); foreach($groups as $group){ foreach($categories as $category){ $exists = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('select id_category, id_group from ps_category_group where id_category = "'.$category['id_category'].'" and id_group = "'.$group['id_group'].'"'); if(!$exists) { $categoryObj = new Category($category['id_category'], (int)Context::getContext()->language->id); echo $categoryObj->addGroups(array($group['id_group'])); echo $group['id_group']." added to ".$category['id_category']."<br />"; }else{ echo $group['id_group']." ALREADY added to ".$category['id_category']."<br />"; } } } Hi, just to say this was perfect! Thank you so much! It worked with PS 1.6.1.6. Jalokin is also right. Make sure you use your main domain name. You will see that it worked because the page will show a list of numbers (adding customer_group_id to category_id): 6 added to 11184 6 added to 11185 6 added to 11186 6 added to 11187 6 added to 11188 6 added to 11189 7 added to 1 7 added to 5 7 added to 6 7 added to 7 7 added to 8 7 added to 9 7 added to 16 etc.... Link to comment Share on other sites More sharing options...
Parts Lunacy Posted May 14, 2017 Share Posted May 14, 2017 I needed a sledgehammer approach: add all groups to all categories. I'm new to PrestaShop, so, can't vouch for my code, but, based upon the suggestion above, came up with a script that simply adds all groups to all categories. You save this code as a new page in your PrestaShop site root folder, then load the page in a browser: <?php require(dirname(__FILE__).'/config/config.inc.php'); $groups= Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' SELECT DISTINCT c.* FROM `'._DB_PREFIX_.'group` c '); $categories = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' SELECT DISTINCT c.* FROM `'._DB_PREFIX_.'category` c LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (c.`id_category` = cl.`id_category` AND cl.`id_lang` = '.(int)Context::getContext()->language->id.') '); foreach($groups as $group){ foreach($categories as $category){ $exists = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('select id_category, id_group from ps_category_group where id_category = "'.$category['id_category'].'" and id_group = "'.$group['id_group'].'"'); if(!$exists) { $categoryObj = new Category($category['id_category'], (int)Context::getContext()->language->id); echo $categoryObj->addGroups(array($group['id_group'])); echo $group['id_group']." added to ".$category['id_category']."<br />"; }else{ echo $group['id_group']." ALREADY added to ".$category['id_category']."<br />"; } } } I think you are my new best friend......... I started doing this manually, then thought there had to be a better way....Found this and I have to say, over 500 categories and it worked a treat on 1.6.1.3........THANK YOU! Now going to setup extra customer groups!!!! Link to comment Share on other sites More sharing options...
goblin Posted October 1, 2017 Share Posted October 1, 2017 Thanks for the script! I launched twice in few seconds and it didn't report "ALREADY added"... so I checked and found a little mistake, the query for the check doesn't manage the custom tables prefix, so for me the query always fails and the var $exists is always false I fixed replacing the table in "$exists =" row : from ps_category_group with this from `'._DB_PREFIX_.'category_group` Link to comment Share on other sites More sharing options...
assault3r Posted March 19, 2018 Share Posted March 19, 2018 Add this code in AdminGroupsController.php before return in processSave function. Link to comment Share on other sites More sharing options...
dani Posted December 13, 2018 Share Posted December 13, 2018 On 3/28/2014 at 4:00 AM, Y Talansky said: need to add with sql to table ps_category_group for id_category add id_group you can use this script to and then access in your browser see below <?php require(dirname(__FILE__).'/config/config.inc.php'); if ($_SERVER["REQUEST_METHOD"] == "POST") { $new_group = $_POST["new_group"]; $categories = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' SELECT DISTINCT c.* FROM `'._DB_PREFIX_.'category` c LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (c.`id_category` = cl.`id_category` AND cl.`id_lang` = '.(int)Context::getContext()->language->id.') '); foreach($categories as $category){ $categoryObj = new Category($category['id_category'], (int)Context::getContext()->language->id); $categoryObj->addGroups(array($new_group)); } echo 'Updated'; } else { echo' <form method="post" action="'.$_SERVER["PHP_SELF"].'"> Enter New Group id: <input type="text" name="new_group"> <input type="submit" name="update" > </form>'; } ?> Wow, this is great! Link to comment Share on other sites More sharing options...
jm16 Posted January 12, 2020 Share Posted January 12, 2020 Hello, how could I modify it for Prestashop 1.7.6 please? Link to comment Share on other sites More sharing options...
Antakarana Posted June 10, 2020 Share Posted June 10, 2020 En 12/1/2020 a las 10:30 PM, jm16 dijo: Hello, how could I modify it for Prestashop 1.7.6 please? Hi Same request here..... 1.7.6.5 Thanks Link to comment Share on other sites More sharing options...
Faceman2k20 Posted July 16, 2020 Share Posted July 16, 2020 Pretty sure I fixed this just by changing the one hardcoded "ps_" prefix to the newer "rczu_" prefix. Change that one part on line 17 to your database prefix and it should work. Here's what I used: <?php require(dirname(__FILE__).'/config/config.inc.php'); $groups= Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' SELECT DISTINCT c.* FROM `'._DB_PREFIX_.'group` c '); $categories = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' SELECT DISTINCT c.* FROM `'._DB_PREFIX_.'category` c LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (c.`id_category` = cl.`id_category` AND cl.`id_lang` = '.(int)Context::getContext()->language->id.') '); foreach($groups as $group){ foreach($categories as $category){ $exists = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('select id_category, id_group from rczu_category_group where id_category = "'.$category['id_category'].'" and id_group = "'.$group['id_group'].'"'); if(!$exists) { $categoryObj = new Category($category['id_category'], (int)Context::getContext()->language->id); echo $categoryObj->addGroups(array($group['id_group'])); echo $group['id_group']." added to ".$category['id_category']."<br />"; }else{ echo $group['id_group']." ALREADY added to ".$category['id_category']."<br />"; } } } ?> Link to comment Share on other sites More sharing options...
jgriff89 Posted October 5, 2020 Share Posted October 5, 2020 Hi, If you use Prestatools (free), you can add group access to all categories in a couple of clicks using category edit. Works with PS 1.7 or 1.6 Link to comment Share on other sites More sharing options...
WaxDev Posted October 29, 2020 Share Posted October 29, 2020 Hi, There's also a module on Prestashop's addon store which allows you to do this in a couple of clicks : https://addons.prestashop.com/en/customer-administration/48181-customer-groups-access-to-product-categories-manager.html (Works with PS 1.7 and 1.6) 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