Jump to content

Group access - massively enable new customer group in all existing categories on the site


ballashop

Recommended Posts

2 hours ago, 4you.software said:

Hi @4you.software  I'm trying to make the suggested change on the link but is not clear to me where I have to insert the first code, can you kindly suggest me?

Thanks for any reply.

Balla

Link to comment
Share on other sites

20 minutes ago, 4you.software said:

./controllers/admin/AdminGroupsController.php

Hi @4you.software sorry but I explained myself wrong, not which file but inside the code, exactly where does the change go?

Unfortunately, from the tutorial, on the first code it doesn't show exactly where

thanks for any reply.

balla

Link to comment
Share on other sites

1. find function renderForm()

2. add before

'type' => 'group_discount_category

 

[
                    'type' => 'switch',
                    'label' => $this->trans('Show prices', [], 'Admin.Shopparameters.Feature'),
                    'name' => 'show_prices',
                    'required' => false,
                    'class' => 't',
                    'is_bool' => true,
                    'values' => [
                        [
                            'id' => 'show_prices_on',
                            'value' => 1,
                            'label' => $this->trans('Yes', [], 'Admin.Global'),
                        ],
                        [
                            'id' => 'show_prices_off',
                            'value' => 0,
                            'label' => $this->trans('No', [], 'Admin.Global'),
                        ],
                    ],
                    'hint' => $this->trans('Customers in this group can view prices.', [], 'Admin.Shopparameters.Help'),
                    'desc' => $this->trans('Need to hide prices for all groups? Save time, enable catalog mode in Product Settings instead.', [], 'Admin.Shopparameters.Help'),
                ],
                [
                    'type' => 'switch',
                    'label' => $this->trans('Assign to all categories', [], 'Admin.Shopparameters.Feature'),
                    'name' => 'all_cat',
                    'required' => false,
                    'class' => 't',
                    'is_bool' => true,
                    'values' => [
                        [
                            'id' => 'all_cat_on',
                            'value' => 1,
                            'label' => $this->trans('Yes', [], 'Admin.Global'),
                        ],
                        [
                            'id' => 'all_cat_off',
                            'value' => 0,
                            'label' => $this->trans('No', [], 'Admin.Global'),
                        ],
                    ],
                    'hint' => $this->trans('Customers in this group can access to all categories. Leave on "NO" if you want to assign them manually.', [], 'Admin.Shopparameters.Help'),
                ],

 

3. find function processSave()

4. add after

$this->updateRestrictions();

5. create new function after processSave()

public function access_all($group)
    {
        $id_group = (int)$group->id;
        $assign_to_all = (bool)Tools::getValue('all_cat');
        $get_categories = Db::getInstance()->executeS('SELECT id_category FROM '._DB_PREFIX_.'category WHERE id_category > 1;');

        if ($assign_to_all && $id_group && $get_categories) {
            foreach ($get_categories as $category){
                Db::getInstance()->insert('category_group', array(
                    'id_category' => (int)$category['id_category'],
                    'group'      => (int)$id_group
                ),false, true, Db::INSERT_IGNORE);
            }
        }
    }

 

Edited by 4you.software (see edit history)
  • Thanks 1
Link to comment
Share on other sites

  • 1 year later...
On 3/17/2022 at 6:15 PM, ps8moduly.cz said:

1. find function renderForm()

2. add before

'type' => 'group_discount_category

 

[
                    'type' => 'switch',
                    'label' => $this->trans('Show prices', [], 'Admin.Shopparameters.Feature'),
                    'name' => 'show_prices',
                    'required' => false,
                    'class' => 't',
                    'is_bool' => true,
                    'values' => [
                        [
                            'id' => 'show_prices_on',
                            'value' => 1,
                            'label' => $this->trans('Yes', [], 'Admin.Global'),
                        ],
                        [
                            'id' => 'show_prices_off',
                            'value' => 0,
                            'label' => $this->trans('No', [], 'Admin.Global'),
                        ],
                    ],
                    'hint' => $this->trans('Customers in this group can view prices.', [], 'Admin.Shopparameters.Help'),
                    'desc' => $this->trans('Need to hide prices for all groups? Save time, enable catalog mode in Product Settings instead.', [], 'Admin.Shopparameters.Help'),
                ],
                [
                    'type' => 'switch',
                    'label' => $this->trans('Assign to all categories', [], 'Admin.Shopparameters.Feature'),
                    'name' => 'all_cat',
                    'required' => false,
                    'class' => 't',
                    'is_bool' => true,
                    'values' => [
                        [
                            'id' => 'all_cat_on',
                            'value' => 1,
                            'label' => $this->trans('Yes', [], 'Admin.Global'),
                        ],
                        [
                            'id' => 'all_cat_off',
                            'value' => 0,
                            'label' => $this->trans('No', [], 'Admin.Global'),
                        ],
                    ],
                    'hint' => $this->trans('Customers in this group can access to all categories. Leave on "NO" if you want to assign them manually.', [], 'Admin.Shopparameters.Help'),
                ],

 

3. find function processSave()

4. add after

$this->updateRestrictions();

5. create new function after processSave()

public function access_all($group)
    {
        $id_group = (int)$group->id;
        $assign_to_all = (bool)Tools::getValue('all_cat');
        $get_categories = Db::getInstance()->executeS('SELECT id_category FROM '._DB_PREFIX_.'category WHERE id_category > 1;');

        if ($assign_to_all && $id_group && $get_categories) {
            foreach ($get_categories as $category){
                Db::getInstance()->insert('category_group', array(
                    'id_category' => (int)$category['id_category'],
                    'group'      => (int)$id_group
                ),false, true, Db::INSERT_IGNORE);
            }
        }
    }

 

If anyone copies this please update the insert statement in access_all to :

Db::getInstance()->insert('category_group', array(
                    'id_category' => (int)$category['id_category'],
                    'id_group'      => (int)$id_group
                ),false, true, Db::INSERT_IGNORE);

 

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