Jump to content

New Customer Group to See All Categories


Recommended Posts

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

  • 5 months later...

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

  • 5 months later...
  • 3 weeks later...
  • 4 months later...

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 by Y Talansky (see edit history)
  • Like 3
Link to comment
Share on other sites

  • 1 year later...
  • 2 weeks later...
  • 6 months later...

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 by amoswright (see edit history)
  • Like 1
  • Thanks 1
Link to comment
Share on other sites

  • 2 months later...
  • 2 months later...
  • 3 months later...

 

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 by Fred Fournier (see edit history)
Link to comment
Share on other sites

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 by jalokin80 (see edit history)
Link to comment
Share on other sites

  • 1 month later...

 

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

  • 1 month later...

 

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

  • 4 months later...

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

  • 5 months later...
  • 8 months later...
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

  • 1 year later...
  • 4 months later...
  • 1 month later...

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

  • 2 months later...
  • 4 weeks 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...