Jump to content
garywright

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

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

 

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)

Share this post


Link to post
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)

Share this post


Link to post
Share on other sites

 

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....

Share this post


Link to post
Share on other sites

 

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!!!!

Share this post


Link to post
Share on other sites

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`

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites

Hello, how could I modify it for Prestashop 1.7.6 please?

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More