Address Custom Attributes in Order summary and Order confirmation email

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
8 anni tempo fa
Hello, I'm pretty new to Nop and i've a problem.

I add a Custom Attribute to customer address through the dedicated form.

Now I would show Address Custom Attributes in Checkout Summary and add them in Order emails.

How can I do this?
I changed
/Themes/<mytheme>/Views/CheckOut/ShippingAddress.cshtml
and
/Themes/<mytheme>/Views/CheckOut/BillingAddress.cshtml

adding this code

@if (item.CustomAddressAttributes.Count > 0){
  foreach(var attr in item.CustomAddressAttributes) {
  <div class="custom">
    @attr.Name: @attr.DefaultValue
  </div>
  }
}

and changed

/Themes/<mytheme>/Views/ShoppingCart/_OrderReviewData.cshtml

adding this code

@if (Model.BillingAddress.CustomAddressAttributes.Count > 0){
  foreach(var attr in Model.BillingAddress.CustomAddressAttributes) {
    <div class="custom">
      @attr.Name: @attr.DefaultValue
    </div>
  }
}

and
@if (Model.ShippingAddress.CustomAddressAttributes.Count > 0){
  foreach(var attr in Model.ShippingAddress.CustomAddressAttributes) {
    <div class="custom">
      @attr.Name: @attr.DefaultValue
    </div>
  }
}

but it seems that custom attributes are not loaded in theese views.

Any idea or suggests?

Thank you in advance
Stefano
8 anni tempo fa
You should map values for CustomAddressAttributes.
You need little customization on source code in CheckoutController

In the protected virtual CheckoutBillingAddressModel PrepareBillingAddressModel action you will find the following code

addressModel.PrepareModel(
                   address: address, 
                    excludeProperties: false,
                    addressSettings: _addressSettings,
                    addressAttributeFormatter: _addressAttributeFormatter);
                model.ExistingAddresses.Add(addressModel);


Add more two parametrs
 addressAttributeService: _addressAttributeService,
                    addressAttributeParser:_addressAttributeParser,


Your code will look like

addressModel.PrepareModel(
                    address: address,
                    excludeProperties: false,
                    addressSettings: _addressSettings,
                    addressAttributeService: _addressAttributeService,
                    addressAttributeParser:_addressAttributeParser,
                    addressAttributeFormatter: _addressAttributeFormatter);


Follow Same process for PrepareShippingAddressModel
8 anni tempo fa
And also follow the same process for OrderReviewData ...Bind data with model .. like above ...You find it  in the ShoppingcartController    .... in  protected virtual void PrepareShoppingCartModel Action in   #region Order review data
8 anni tempo fa
Ok, my mistake, io don't specify that I'm using one page checkout but Sohel suggests help me to resolve my problem.

For One Page Checkout I'd to had suggested code in method "PrepareShoppingCartModel" of the ShoppingCartController.

For this controller I also had _addressAttributeService and _addressAttributeParser fields and add pass them in contructor sign.

Thank you very much for your help!
6 anni tempo fa
any ideas how to do it since 3.90 uses model factories for Nop.Web project?

addressModel.PrepareModel is not working anymore since it has been removed from MappingExtensions.
6 anni tempo fa
My example model in 3.70

public class xxxModel : BaseNopModel
    {
        public xxxModel()
        {
            CustAddress = new AddressModel();
            
        }


        public AddressModel CustAddress { get; set; }

}



there used to be PrepareModel in MappingExtensions so I was using in my controller(3.70) as


model.CustAddress.PrepareModel(null, true, _addressSettings,
                _localizationService, _stateProvinceService,
                EngineContext.Current.Resolve<IAddressAttributeService>(),
                EngineContext.Current.Resolve<IAddressAttributeParser>(),
                _addressAttributeFormatter,
                () => _countryService.GetAllCountriesForBilling(), true,
                _workContext.CurrentCustomer);


but now we have factories in 3.90. How can I do the same action in 3.90 using AddressModelFactory. I can see the PrepareModel from MappingExtensions moved to AddressModelFactory as PrepareAddressModel. When I try to use it I get null reference exception. Any ideas?
4 anni tempo fa
Is there a way to do this with the No Source version of NopCommerce ?
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.