How to add a new column in customer register?

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
Il y a 1 an
This is the steps I tried, but  it is NOT working, maybe I missed something?

1. Manually add a column in customer table, eg.
alter table Customer add column groupowner nvarchar(50)

2. Data model/Entity:
Solution: Libraries/Nop.Core/Domain/Customers/Customer.cs
Add the code:
  public string groupowner { get; set; }

3. EntityMap
Solution: Nop.data / Mapping / Builders / Customers / CustomerBuilder.cs
Add the code:
WithColumn(nameof(Customer.groupowner)).AsString(1000).Nullable()

4. EntityModel / Presentation Model

Solution: Presentation/Nop.Web/Areas/Admin/Models/Customers/CustomerModel.cs
Add the code:
[NopResourceDisplayName("Admin.Customer.Categories.Fields.groupowner ")]
public string groupowner { get; set; }

Solution: Presentation/Nop.Web/Areas/Admin/Validators/Customers/CustomerValidator.cs
Add the code:
RuleFor(m => m.groupowner).Length(0, 255);

5. View Model
Solution: Presentation/Nop.Web/Areas/Admin/Views/Customer/_CreateOrUpdate.Info.cshtml
Add the code
        <div class="form-group">
            <div class="col-md-3">
                <nop-label asp-for="groupowner" />
            </div>
            <div class="col-md-9">
                <nop-editor asp-for="groupowner" />
                <span asp-validation-for="groupowner"></span>
            </div>
        </div>

Then, I rebuild the solution and run the application, but looks like the register page did not update as expected, anything I missed? thanks.
Il y a 1 an
It seems to be ok

Can you please brief what you expected and what issue you facing ??

The textbox not showing or in post method its not updated

If you want to store into db.
You need to do coding in the customer post method
Il y a 1 an
I did not use custom customer attribute here, since I want to use this new column(future maybe  3-4 new columns) to filte the orders in Admin in the future. This is only the 1st step.
Il y a 1 an
Expection:
1. Display the more  new columns in customer registration page, and store the data into the database
2. Use these new columns as query condition  in filter in Admin page in the future.
Il y a 1 an
You changed the Admin Customer page but you did not change the register page ?

nopCommerce_4.40.4_Source\Presentation\Nop.Web\Views\Customer\Register.cshtml

Do you then plan to debug it using Visual Studio ?
Il y a 1 an
Thanks for the quick response. I am trying to put below code into:
Presentation\Nop.Web\Views\Customer\Register.cshtml

                    @if (Model.groupownerEnabled)
                    {
                        <div class="inputs">
                            <label asp-for="groupowner" asp-postfix=":"></label>
                            <input asp-for="groupowner" />
                            @if (Model.groupownerRequired)
                            {
                                <nop-required />
                            }
                            <span asp-validation-for="groupowner"></span>
                        </div>
                    }
rebuild/run,  but still no more columns displayed in registration page. any idea? thanks.

in RegisterModel.cs, I also added the following:

        public bool groupownerEnabled { get; set; }
        public bool groupownerRequired { get; set; }
        // The NopResourceDisplayName provides the "key" used during localization
        // Keep an eye out for more about localization in future blogs
        [NopResourceDisplayName("Admin.Customers.Customers.Fields.groupowner")]
        public string groupowner { get; set; }
Il y a 1 an
 @if (Model.groupownerEnabled)

as you have added this field bool value
so I assume , you are fetching this value from setting ,

so while call the get method of register did you added things in customerFactory
if not just add the things into the factory and assign to group owner enable

this might be cause not to display
Il y a 1 an
Yes you are right, after removing:
@if (Model.groupownerEnabled)
I can see the new column in register page. How can I set the anbled/required? there are 2 places for CustomerFactory:
1. Presentation/Nop.Web/Areas/Admin/Factoryies/CustomerModelFactory.cs
2. Presentation/Nop.Web/Factories/CustomerModelFactory.cs

which one I need to select? what's the difference? and how to change? thanks.
Il y a 1 an
All the files in \Admin are associated with the Admin Views

Yidna wrote:
Presentation\Nop.Web\Areas\Admin\Views/Customer\_CreateOrUpdate.Info.cshtmll
1. Presentation/Nop.Web/Areas/Admin/Factoryies/CustomerModelFactory.cs

Yidna wrote:
Presentation\Nop.Web\Views\Customer\Register.cshtml
2. Presentation/Nop.Web/Factories/CustomerModelFactory.cs

Usually a field like groupownerEnabled would be associated with a setting so you can enable disable via the plugin config view as required
Il y a 1 an
Basically, if you have added the setting with the name of groupownerEnabled
so it needs to pass with the model factory,

if you did not create the setting of enabled disabled you need to add a setting like a general setting there

and you need to add 2 different side
1. for admin and 2. Front side

1. Admin side changes :
you can add like this check screenshot

same as front side add the setting and field
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.