Jump to content

Category access for new customers group


Recommended Posts

Hello,

 

i'm using PS 1.4.7.0 and i've created a new customer group.

 

I have about 300 categories and i want to grant the access to all these categories for this new customers group.

 

I've seen that i have to go into all categories and select the checkbox, but i would like to know if is it possibile to do this automatically.

 

How can I do?

 

Thanks

Link to comment
Share on other sites

you can do this by adding the correct entries to the ps_category_group database table. each row in the table is the category_id and the group_id

 

so assuming you have categories 1, 2 and 3, and your group_id is 2, then you would have 3 entries

1, 2

2, 2

3, 2

Link to comment
Share on other sites

  • 2 months later...
  • 8 months later...
  • 3 weeks later...
  • 5 weeks later...
  • 6 months later...

Hi,

 

It is necessary to create a file in PrestaShop root (updCategoryGroup.php), and call it, it can be done even from browser line -myStore.com/updCategoryGroup.php

Then add the following code:

 

<?php

 

require(dirname(__FILE__).'/config/config.inc.php');

 

$new_group = 4; // there is ID of 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));

}

 

Best regards.

Unlike

Valérie Assetskaya/ Valerie Assetskaya

Responsable du Soutien Clientèle à BelVG/Support manager at BelVG

module-presta.com - modules Prestashop de BelVG/ BelVG PrestaShop modules

 

 

 

------

 

Close it

  • Like 1
Link to comment
Share on other sites

  • 2 months later...
  • 2 months later...
  • 2 weeks later...

I've got a lot of group more than 4000 since i need to set up customer discount on category and the only way is creating 1 group for each customer.

 

I've got 4000 group and 40 categories i will obtain 160000 row .... just a bit weird ...

 

Is there a way to disable group access ?

 

thank you in advance for any good reply ;-)

Link to comment
Share on other sites

  • 9 months later...

Just execute this SQL comman via your phpmyadmin or download adminer. Super fast and easy all in one SQL command no complicated cycles.
 

INSERT IGNORE INTO `ps_category_group` (`id_category`,`id_group`)
SELECT DISTINCT `id_category`, 8 /*this number is your id group*/ FROM `ps_category`

Dont forget to change your DB_PREFIX

Edited by Cerhan (see edit history)
  • Like 4
Link to comment
Share on other sites

  • 8 months later...
  • 3 months later...
  • 5 months later...
  • 1 year later...
On 1/27/2015 at 4:53 AM, Cerhan said:

Just execute this SQL comman via your phpmyadmin or download adminer. Super fast and easy all in one SQL command no complicated cycles.
 


INSERT IGNORE INTO `ps_category_group` (`id_category`,`id_group`)
SELECT DISTINCT `id_category`, 8 /*this number is your id group*/ FROM `ps_category`

Dont forget to change your DB_PREFIX

Hi @Cerhan

There have been a couple of different questions in this thread so can I please confirm before I run the SQL command...

The purpose of this command is to assign ALL categories to the specified customer group as per original poster question?

Thanks

Link to comment
Share on other sites

Hi,
yes it does. Although i didn't work with prestashop for a while, so it's up to you to test if it still works (it should). I strongly recommend to run it first on some test environment, or at least backup your database.

Link to comment
Share on other sites

18 hours ago, Cerhan said:

Hi,
yes it does. Although i didn't work with prestashop for a while, so it's up to you to test if it still works (it should). I strongly recommend to run it first on some test environment, or at least backup your database.

Thanks for the reply and for sharing the command.  I ran the command on a test store and it worked well on v1.6.1.18

Thanks again

Link to comment
Share on other sites

  • 2 years later...

@inspectaclueso @Cerhan

Hi

I want to add a new user group to all the categories on a PS 1.7.6.5...

In my case the new group ID is "9" and my DB_PREFIX is the following one:

image.png.5aa767f015a52b1dcbe2729fc8bdb619.png

So can you tell me if the script should be like this?

INSERT IGNORE INTO `prstshp_category_group` (`id_category`,`id_group`)

SELECT DISTINCT `id_category`, 9 FROM `prstshp_category`

😅

Thanks in advance!

Link to comment
Share on other sites

hace 1 hora, Antakarana dijo:

@inspectaclueso @Cerhan

Hi

I want to add a new user group to all the categories on a PS 1.7.6.5...

In my case the new group ID is "9" and my DB_PREFIX is the following one:

image.png.5aa767f015a52b1dcbe2729fc8bdb619.png

So can you tell me if the script should be like this?

INSERT IGNORE INTO `prstshp_category_group` (`id_category`,`id_group`)

SELECT DISTINCT `id_category`, 9 FROM `prstshp_category`

😅

Thanks in advance!

I'm gonna answer myself....

 

Yes... it works!!! :D

 

Link to comment
Share on other sites

  • 3 years later...

Hi all, this is a weird problem of Prestashop, there should be a better way of doing this by now that doesn't require us to run scripts.

Here's a better way of achieving this with error handling functionalities:

DELIMITER //
CREATE PROCEDURE GrantAccessToAllCategories()
BEGIN
  DECLARE CONTINUE HANDLER FOR SQLEXCEPTION
  BEGIN
    -- An error has occurred, rollback the transaction
    ROLLBACK;
  END;

  START TRANSACTION;

  INSERT INTO ps_category_group (id_category, id_group)
  SELECT ps_category.id_category, XX
  FROM ps_category
  WHERE NOT EXISTS (
    SELECT 1 
    FROM ps_category_group 
    WHERE ps_category_group.id_category = ps_category.id_category 
    AND ps_category_group.id_group = XX
  );

  COMMIT;
END//
DELIMITER ;

This script works works database prefixes PS_ (if yours is different you should change this value). Also change the XX with the actual Group ID you want to grant permissions to all the categories.

NB: I haven't personally tested it, so please be cautious and make you backups.

Link to comment
Share on other sites

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