Thanks so much ILYAS PATEL, the new column is working in register page now. But looks like the value of groupowner I inputed during the customer registration cannot be saved to the database. Need to change something as well? :-) thanks again.
If you want to store the groupowner you need to add this into the customer register POST METHOD
When you click on register add debug in post method so you will get idea and add the logic here just need to do this things before insert record You need to assign model value into customer object Customer.groupowner= model.groupowner Rest insert code is already done
Now I want to display the value of groupowner in the page of "My account - Customer info", what I did are: CustomerInfoModel.cs: [NopResourceDisplayName("GroupOwner")] public string groupowner { get; set; } info.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> } CustomerValidator.cs RuleFor(x => x.groupowner).Length(0, 255);
Rebuild/Run, I only can see the page in "My account - Customer info", but no value/data in the column GroupOwner, I am sure it has data in the database. How to get the data out from the database? thanks.
After setting the below in PrepareCustomerInfoModelAsync Solution: Presentation/Nop.Web/Areas/Admin/Factoryies/CustomerModelFactory.cs customer.groupowner=model.groupowner The data of groupowner can be displayed normally. However, when I changed the data to another value from page of "My account - Customer info", which cannot be saved successfully.
After debugging the below code in CustomerController.cs, Solution: Presentation/Nop.Web/Controllers/CustomerController.cs model did not accept the new value, anything I missed here?
public virtual async Task<IActionResult> Info() { var customer = await _workContext.GetCurrentCustomerAsync(); if (!await _customerService.IsRegisteredAsync(customer)) return Challenge();
var model = new CustomerInfoModel(); // model = await _customerModelFactory.PrepareCustomerInfoModelAsync(model, customer, false); model = await _customerModelFactory.PrepareCustomerInfoModelAsync(model, await _workContext.GetCurrentCustomerAsync(), false); return View(model); }
I also checked CustomerController.cs in admin side. I have put the below code in it, fyi. Solution: Presentation/Nop.Web/Areas/Admin/Controllers/CustomerController.cs public virtual async Task<IActionResult> Create(CustomerModel model, bool continueEditing, IFormCollection form) ...... if (_customerSettings.groupownerEnabled) await _genericAttributeService.SaveAttributeAsync(customer, NopCustomerDefaults.groupownerAttribute, model.groupowner);
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.