Add Role at registring

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
4 years ago
Hello everyone,

Is the a way to add one more Role at registring.

the standard role becomes 'Registred' after the registration,
but for displaying different prices according to the type of customer (roles), i am using tier prices :

- Role 'CLIENT00' for standard customers => Tier Prices X
- Role 'PRO10' for Customers Pro  => Tier Prices Y

So for new customers, at registring i want to automaticaly add the Rôle 'CLIENT00' in addition to 'Registred' Rôle.

(im using nop 3.90)

Thanks for your help
4 years ago
It is easy.
When you already add new roles,
you change the method "RegisterCustomer" in "\src\Libraries\Nop.Services\Customers\CustomerRegistrationService.cs",

//add to 'Registered' role
            var registeredRole = _customerService.GetCustomerRoleBySystemName(NopCustomerDefaults.RegisteredRoleName);
            if (registeredRole == null)
                throw new NopException("'Registered' role could not be loaded");
            //request.Customer.CustomerRoles.Add(registeredRole);

In here you can add any role you want.
4 years ago
Thank you very much for your help,

I already have made quite many changing into our website but always directly into cshtml pages and never into a .cs source code

So after insert some new lines into the CustomerRegistrationService.cs file as necessary to add a new role, at the customer registration  :

//New role
var CLI00Role = 'CLI00';
// 'CLI00' is already recorded into the rôle table as a systemname
request.Customer.CustomerRoles.Add(CLI00Role );  

but the next steps are very new for me :

Please, is there a topics, a doc, or a process to assume the different changes steps after ?

With all precautions with visual studio : to compil, regenerate the service, save and copying all new dll

Regards
4 years ago
var CLI00Role = 'CLI00';

You can't add to role by using the role name string.  (And, those single quotes are not correct for C# string anyway.)
See above:  ... GetCustomerRoleBySystemName()

Yes, you need Visual Studio to Rebuild the solution, and then deploy the dll(s).   If you are not a C# / nopCommerce developer, then you should find someone to help you.  (Although, I recommend you/they create a plugin rather than modifying core code)
4 years ago
yes you r right :

at CustomerRegistrationService.cs i have modify by :


            //add New role 'CLI00' *********************************************************************
            var CLI00Role = _customerService.GetCustomerRoleBySystemName(SystemCustomerRoleNames.CLI00);
            // 'CLI00' is already recorded into the rôle table as a systemname
            request.Customer.CustomerRoles.Add(CLI00Role);
            //******************************************************************************************


and add at the SystemCustomerRoleNames.cs


public static string CLI00 { get { return "CLI00"; } }


and the new role CLI00 i recorded into the role table.

So, when i generate that service in debug mode : all is right :


1> ------ Start global regeneration: Project: Nop.Core, Configuration: Debug Any CPU ------
1> Nop.Core -> D: \ My Web Sites \ nopcomsrc \ Libraries \ Nop.Core \ bin \ Debug \ Nop.Core.dll
2> ------ Beginning of global regeneration: Project: Nop.Data, Configuration: Debug Any CPU ------
2> Nop.Data -> D: \ My Web Sites \ nopcomsrc \ Libraries \ Nop.Data \ bin \ Debug \ Nop.Data.dll
3> ------ Start of global regeneration: Project: Nop.Services, Configuration: Debug Any CPU ------
3> Nop.Services -> D: \ My Web Sites \ nopcomsrc \ Libraries \ Nop.Services \ bin \ Debug \ Nop.Services.dll
========== Global regeneration: 3 passed, 0 failed, 0 was ignored ==========


but in release mode there is a bug with the third service line :

3>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets(3533,5): error MSB6006: stop "sgen.exe" with code 1.


could i simply replace that 3 dll from the debug folder to the site ?
4 years ago
You could, but I would not recommend running assemblies compiled in debug mode in production (it will affect performance / memory).

How are you building the project?  In Visual Studio, or with command line?

Maybe one of these solutions could help:
https://social.msdn.microsoft.com/Forums/vstudio/en-US/f7f4c51f-daf6-44c5-b214-cf312b8f625f/sgenexe-exited-with-code-1?forum=msbuild
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.