Adding an additional field to the Newsletter Email User

1 mese tempo fa
I am working on a project that requires a user to register and enter a special code to access a specific area of the Web site that I am developing.  I am using the existing nop4.4 Newsletter infrastructure to collect the Email from the user that I then verified via the nopEmail verification process.  I would like to be able to identify these users for special marketing purposes.  How would I add a tag to this specific registration for special handling later on?

Please advise on an approach to create a new database field that I can user later to filter; or maybe there is a way to add these specific users to a brand new category that I create, instead of the NewsLetter Users list.
1 mese tempo fa
One easy way is create a new customer role and then add the customer to the role
Later you can check if the customer is in the the role to gain access to special functions
You can also use the Standard Customer funtions to search and manage the customers in the role
For more complex operations you can use ACL to manage what else the role can do

See code from src\Libraries\Nop.Services\Customers\CustomerService.cs

var guestRole = await GetCustomerRoleBySystemNameAsync(NopCustomerDefaults.GuestsRoleName);

if (guestRole is null)
    throw new NopException("'Guests' role could not be loaded");

await AddCustomerRoleMappingAsync(new CustomerCustomerRoleMapping { CustomerRoleId = guestRole.Id, CustomerId = backgroundTaskUser.Id });

public virtual async Task<bool> IsGuestAsync(Customer customer, bool onlyActiveCustomerRoles = true)
    return await IsInCustomerRoleAsync(customer, NopCustomerDefaults.GuestsRoleName, onlyActiveCustomerRoles);
1 mese tempo fa
Thank Yo for the direction.  I was wondering the following:
Currently, the Newsletter Subscription is using the NewsletterController.cs to email the user when they fill-out the Subscription Email Newsletter input.   This is happening inside the SubscribeNewsletter(string email, bool subscribe) method.  Specifically, the user is being added to the Newsletter group, utilizing this piece of code:

                    subscription = new NewsLetterSubscription
                        NewsLetterSubscriptionGuid = Guid.NewGuid(),
                        Email = email,
                        Active = false,
                        StoreId = (await _storeContext.GetCurrentStoreAsync()).Id,
                        CreatedOnUtc = DateTime.UtcNow
                    await _newsLetterSubscriptionService.InsertNewsLetterSubscriptionAsync(subscription);

I am able to distinguish between users that are sent to register for a specific purpose.  How do I use  a similar block of code to add the specific users to a new role, other than Newsletter?  For example, If I create a new role, say, designers; I can add them to the Designer role at this point.  I believe that the Email confirmation will work either way.  I do not think it matters which groups they are added to during Email processing.  Am I correct?

That would save me time later from having to add them manually to a new role that I create, as you recommended.  What do you think?  Is that possible?
1 mese tempo fa
RE: "...I can add them to the Designer role at this point"
Not necessarily.  Firstly, there is no "Newsletter Group".  (Nor 'Role', unless you create one).  There is a NewsLetterSubscription, and thus the main problem is that you don't have to be logged in to subscribe, so you don't have a customer id at that point.  

RE: "...nopEmail verification process..."
I assume you mean you've set "Registration method: Email validation is required after registration".   I think in any case,  you could probably tap in to the registration process (ideally via plugin), to lookup the registration email address to see if it's in the NewsLetterSubscription, and if so, put the customer in the role at that time.
1 mese tempo fa
Very good point about not having a CustomerID.
Under Promotions, there is a Newsletter Subscribers Group.  Can I create a similar group to add the users that I am referring to during the Subscription process?
1 mese tempo fa
I still don't know what you mean by "Group".  You can add email/Newsletter subscribers by importing a list of subscribers from an external CSV file.
1 mese tempo fa
I am not clear in my question.  Sorry about that.  The Customer roles defines Groups and Roles to describe how to use them to provides access to specific actions, such as a discount to a group of customers, etc.  
What I am asking is the following:

During the Newsletter subscription process, the Customer or Web site visitor is added to a Newsletter Subscriber group:

How do I create a similar group to add some specific Customers that are signing-up for a special promotion that I am running?  BTW, I am using a similar sign-up process to ask them to join.
1 mese tempo fa
Newsletter Subscribers is a system or internal "Group" as such managed via a NewsletterSubscription
table . So the way to make another one is to create a new NewsletterSubscription table then copy and paste all the code that relates to Newsletter subscriptions to manage it. Or you add a new field to the exisiting table and change existing code.

That is why I suggested the other idea of using customer roles. Now I know when you subscribe to the newsletter there is no customer but for your purposes, when they subcribe to the special promotion you could also automatically create a customer and add them to the newly created "Special Promotion" Role which will then allow you to manage then as a Group.
1 mese tempo fa
@Yidna,  I like the idea or duplicating the existing Newsletter subscription process.  I am doing that now.  I created a new model with the existing code and renamed it.  then, I added an extra step to email me when a client signs-up.  I currently need to take it further and find the whole process flow that also adds the users to Newsletter table and also find a way to add that process to the Admin section, just like the Newsletter users.  Would that be a plugin or can I do it directly?
1 mese tempo fa
You can do it directly if you want. There is no hard rule.
The reason you make a plugin is just to keep things together to manage it easier and later for upgrading or to make a function available for others.
You can always make a plugin later after prototyping if required