How to skip some of billing address input fields? I need to make them unnecessary.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
3 years ago
we have nopcommerce 3.90

i use guest checkout and I want to disable some required fields in billing address

i found this code in \Views\Shared\_CreateOrUpdateAddress.cshtml

@if (Model.CountryEnabled)
    {
        <div class="inputs">
            @Html.LabelFor(model => model.CountryId, new { }, ":")
                @Html.DropDownListFor(model => model.CountryId, Model.AvailableCountries)
            @Html.RequiredHint()
            @Html.ValidationMessageFor(model => model.CountryId)
        </div>
    }
@if (Model.ZipPostalCodeEnabled)
    {
        <div class="inputs">
            @Html.LabelFor(model => model.ZipPostalCode, new { }, ":")
                @Html.EditorFor(model => model.ZipPostalCode)
            @if (Model.ZipPostalCodeRequired)
            {
                @Html.RequiredHint()
            }
            @Html.ValidationMessageFor(model => model.ZipPostalCode)
        </div>
    }


is it possible to make it without touching the source code? how to do it only in the web version?

thanks.
3 years ago
You can try this to check for guest, and then use "if (!isGuest) ...) " where needed to include fields.
{
     var customer =  EngineContext.Current.Resolve<IWorkContext>.CurrentCustomer;
     var isGuest = customer.Email == null;
}
3 years ago
Like this?


@if (!isGuest)
  {
     var customer =  EngineContext.Current.Resolve<IWorkContext>.CurrentCustomer;
     var isGuest = customer.ZipPostalCode == null;
  }


I tried, it doesn't work.

Also where do I need to put this code?

Inside or outside from this code?

@if (Model.ZipPostalCodeEnabled)
    {
        <div class="inputs">
            @Html.LabelFor(model => model.ZipPostalCode, new { }, ":")
                @Html.EditorFor(model => model.ZipPostalCode)
            @if (Model.ZipPostalCodeRequired)
            {
                @Html.RequiredHint()
            }
            @Html.ValidationMessageFor(model => model.ZipPostalCode)
        </div>
    }
3 years ago
Up the top you put
@model AddressModel
@using Nop.Core;
@using Nop.Core.Infrastructure;
@{
    var customer = EngineContext.Current.Resolve<IWorkContext>().CurrentCustomer;
    var isGuest = customer.Email == null;
}

Then later you can use these variables
@if (Model.ZipPostalCodeEnabled && !isGuest)
{
...
}
3 years ago
@if (Model.ZipPostalCodeEnabled && !isGuest)
{
...
}
[/quote]

Can you please give me full example for ZipCode? And why you use customer.Email ? What if I need other fields not EMAIL? Please, help me
3 years ago
Yidna wrote:
Up the top you put
@model AddressModel
@using Nop.Core;
@using Nop.Core.Infrastructure;
@{
    var customer = EngineContext.Current.Resolve<IWorkContext>().CurrentCustomer;
    var isGuest = customer.Email == null;
}

Then later you can use these variables
@if (Model.ZipPostalCodeEnabled && !isGuest)
{
...
}


Yes. But how to skip the fields?
3 years ago
The check for Email is what indicates whether the customer is a guest or not.  Guests would not have an Email.

Using the zip code was an example.   You replace the existing  
@if (Model.ZipPostalCodeEnabled)
with
@if (Model.ZipPostalCodeEnabled && !isGuest)

If you are wanting to exclude other fields, it would be the same idea of replacing/modifying the @if expression.
3 years ago
New York wrote:
The check for Email is what indicates whether the customer is a guest or not.  Guests would not have an Email.

Using the zip code was an example.   You replace the existing  
@if (Model.ZipPostalCodeEnabled)
with
@if (Model.ZipPostalCodeEnabled && !isGuest)

If you are wanting to exclude other fields, it would be the same idea of replacing/modifying the @if expression.


Thank you so much. I have done as described.

Changed this code:

@if (Model.ZipPostalCodeEnabled && !isGuest)
    {
        <div class="inputs">
            @Html.LabelFor(model => model.ZipPostalCode, new { }, ":")
                @Html.EditorFor(model => model.ZipPostalCode)
            @if (Model.ZipPostalCodeRequired)
            {
                @Html.RequiredHint()
            }
            @Html.ValidationMessageFor(model => model.ZipPostalCode)
        </div>
    }


Then restarted the app.

ZipCode field has gone, but any way when I click NEXT STEP nothing happens.

At the beginning I have this code:

@model AddressModel
@using Nop.Web.Models.Common;
@using Nop.Core;
@using Nop.Core.Infrastructure;
@{
    var customer = EngineContext.Current.Resolve<IWorkContext>().CurrentCustomer;
    var isGuest = customer.Email == null;
}


When I click NEXT nothing happens! ZipCode field is not skipped even though I fill all other fields.
3 years ago
What I want is to skip all the fields in Billing Address except: First Name, Last Name, E-mail and Phone Number.
Then in next step customer checks CHECKBOX for PICKUP if he wants to and then he skips filling shipping address or if customer needs shipping then he fills the detailed shipping address COUNTRY, STATE, CITY, ADDRESS, POSTAL CODE.
3 years ago
Yidna wrote:
Up the top you put
@model AddressModel
@using Nop.Core;
@using Nop.Core.Infrastructure;
@{
    var customer = EngineContext.Current.Resolve<IWorkContext>().CurrentCustomer;
    var isGuest = customer.Email == null;
}

Then later you can use these variables
@if (Model.ZipPostalCodeEnabled && !isGuest)
{
...
}


I tried this and unfortunately it doesn't work :(
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.