Customer Mapping to Registered/Retailer/Wholesaler Role --

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
11 anni tempo fa
Hi,

I have created Different customer roles retailer/wholesalers. When I'm registering user with wholesaler, he is getting mapped to all roles including Registered, Retailer and Wholesaler.

I have modified the below code in \Libraries\Nop.Services\Customers\CustomerRegistrationService.cs:

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

            //Added Code by me

            var customRole = _customerService.GetCustomerRoleBySystemName("Retailer");
            request.Customer.CustomerRoles.Add(customRole);

            var customRole1 = _customerService.GetCustomerRoleBySystemName(SystemCustomerRoleNames.Wholesalers);
            request.Customer.CustomerRoles.Add(customRole1);

Please let me know what wrong I'm doing? And what needs to be done?

Your Inputs are highly appreciable

Thanks,
Ricky
11 anni tempo fa
ricky_maha24 wrote:
Hi,

I have created Different customer roles retailer/wholesalers. When I'm registering user with wholesaler, he is getting mapped to all roles including Registered, Retailer and Wholesaler.

I have modified the below code in \Libraries\Nop.Services\Customers\CustomerRegistrationService.cs:

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

            //Added Code by me

            var customRole = _customerService.GetCustomerRoleBySystemName("Retailer");
            request.Customer.CustomerRoles.Add(customRole);

            var customRole1 = _customerService.GetCustomerRoleBySystemName(SystemCustomerRoleNames.Wholesalers);
            request.Customer.CustomerRoles.Add(customRole1);

Please let me know what wrong I'm doing? And what needs to be done?

Your Inputs are highly appreciable

Thanks,
Ricky


You are adding all three roles to the customer (no logic check whatsoever), so I suppose that's the correct behavior. :D
11 anni tempo fa
Thanks For replying back....

Yes, I understand some Logic check requires here.. But How do I check which role customer has chosen while registering, so that it should add only the chosen role in the DB for that customer?
11 anni tempo fa
ricky_maha24 wrote:
Thanks For replying back....

Yes, I understand some Logic check requires here.. But How do I check which role customer has chosen while registering, so that it should add only the chosen role in the DB for that customer?


You cant do that in service layer, you should leave that to the controller. :D
11 anni tempo fa
Ok.. this what I have done in the controller \Nop.Web\Controllers\CustomerController.cs:

//Added Code in Register Method

            model.CustomerRoles.Add(new SelectListItem() { Text = _localizationService.GetResource("Account.Fields.RolesId"), Value = "0" });

            foreach (var c in _customerService.GetAllCustomerRoles())
            {
                model.CustomerRoles.Add(new SelectListItem() { Text = c.Name, Value = c.Id.ToString() });
            }
            //eND

Please let me know what I need to add here so that it should work as per my requirement.

Thanks,
11 anni tempo fa
ricky_maha24 wrote:
Ok.. this what I have done in the controller \Nop.Web\Controllers\CustomerController.cs:

//Added Code in Register Method

            model.CustomerRoles.Add(new SelectListItem() { Text = _localizationService.GetResource("Account.Fields.RolesId"), Value = "0" });

            foreach (var c in _customerService.GetAllCustomerRoles())
            {
                model.CustomerRoles.Add(new SelectListItem() { Text = c.Name, Value = c.Id.ToString() });
            }
            //eND

Please let me know what I need to add here so that it should work as per my requirement.

Thanks,


This is populating the drop down list from the database. You need another logic to see what is the selected value in the select list, and assign things accordingly. :D
11 anni tempo fa
Yes wooncherk...

I don't know how to achieve it.. I have searched a lot in the code but couldn't find how to do this. Please help wooncherk.

Thanks a lot...
11 anni tempo fa
ricky_maha24 wrote:
Yes wooncherk...

I don't know how to achieve it.. I have searched a lot in the code but couldn't find how to do this. Please help wooncherk.

Thanks a lot...


Hi Ricky,

I can pinpoint the error, or give guidance, but I usually won't show codes here (I'll leave that for paid service, haha). You can try adding logic here [CustomerController.cs, assuming v2.65]:

var registrationRequest = new CustomerRegistrationRequest(customer, model.Email,
                    _customerSettings.UsernamesEnabled ? model.Username : model.Email, model.Password, _customerSettings.DefaultPasswordFormat, isApproved);


Try assigning the customer role before calling this line, and you should be able to save the role. :D
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.