Default Contry on registration form

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
11 years ago
Is there a way to set the default country in the registration page to UK, I have figured out changing the display order put it to the top if the country list, but I would like a way of selected UK by default as most of our customers are based in the uk.

Ok we have some over seas customers.

But I like it so that the uk is the default, with out me having to go and delve through the C# code.
11 years ago
hi.. if you are using nopcommerce 2.6 goto Presentation/Nop.Web/Controllers folder and find CustomerController.cs.

then find the method  

[NopHttpsRequirement(SslRequirement.Yes)]
        public ActionResult Register()


then find the following line. ( line no. 461 & 462)

foreach (var c in _countryService.GetAllCountries())
                {


insert below (line 463) the following code. it'll select default as uk. 80 is the country code for uk in nop database table.

if(c.Id==80)
     model.AvailableCountries.Add(new SelectListItem() { Text = c.GetLocalized(x => x.Name), Value = c.Id.ToString(),Selected=true });
else


http://www.elaamart.com
11 years ago
No NOP 2.5
11 years ago
Tokra30 wrote:
Is there a way to set the default country in the registration page to UK, I have figured out changing the display order put it to the top if the country list, but I would like a way of selected UK by default as most of our customers are based in the uk.

Ok we have some over seas customers.

But I like it so that the uk is the default, with out me having to go and delve through the C# code.

In admin>configuration>countries (example in admin demo) change UK display order
11 years ago
It will still say "Select a country" by default, won't it?
11 years ago
Thanks for the help with the code change I found useful I modified my code to this

if (_customerSettings.CountryEnabled)
            {
                //model.AvailableCountries.Add(new SelectListItem() { Text = _localizationService.GetResource("Address.SelectCountry"), Value = "80" });
                foreach (var c in _countryService.GetAllCountries())
                {

                    if (c.Id==80)
                    {
                        model.AvailableCountries.Add(new SelectListItem() { Text = c.GetLocalized(x => x.Name), Value = c.Id.ToString(), Selected = true });
                    }
                    else
                    {
                        model.AvailableCountries.Add(new SelectListItem() { Text = c.GetLocalized(x => x.Name), Value = c.Id.ToString() });
                    }
                  
                }

Also made the changes in the admin model as well, so the uk is now at the top of the country list.

Thanks all.
11 years ago
Oops the comment out line should read

//model.AvailableCountries.Add(new SelectListItem() { Text = _localizationService.GetResource("Address.SelectCountry"), Value = "0" });
11 years ago
Also moded

[NonAction]
        private void PrepareCustomerInfoModel(CustomerInfoModel model, Customer customer, bool excludeProperties)
{ ...

Changed the following lines...


//model.AvailableCountries.Add(new SelectListItem() { Text = _localizationService.GetResource("Address.SelectCountry"), Value = "0" });
                foreach (var c in _countryService.GetAllCountries())
                {

                    if (model.CountryId == 0)
                    {
                        if (c.Id == 80)
                        {
                            model.AvailableCountries.Add(new SelectListItem() { Text = c.GetLocalized(x => x.Name), Value = c.Id.ToString(), Selected = true });
                        }
                        else
                        {
                            model.AvailableCountries.Add(new SelectListItem() { Text = c.GetLocalized(x => x.Name), Value = c.Id.ToString() });
                        }
                    }
                    else
                    {
                        model.AvailableCountries.Add(new SelectListItem()
                        {
                            Text = c.GetLocalized(x => x.Name),
                            Value = c.Id.ToString(),
                            Selected = c.Id == model.CountryId
                        });
                    }
                    
                }




...}

So if the person dose not put in the country it defaults to the uk on there account page if there is no country selected...
9 years ago
Hey,

Does anyone knows how to get this work on Nop 3.4?
I don't get it to work.

UPDATE
Got it!

You also need do the changes in Nop.Web/Extensions/MappingExtensions.cs on line 133

//model.AvailableCountries.Add(new SelectListItem() { Text = _localizationService.GetResource("Address.SelectCountry"), Value = "0" });
                foreach (var c in loadCountries())
                {
                    if (model.CountryId == 0)
                    {
                        if (c.Id == 74)
                        {
                            model.AvailableCountries.Add(new SelectListItem()
                            {
                                Text = c.GetLocalized(x => x.Name),
                                Value = c.Id.ToString(),
                                Selected = true
                            });
                        }
                        else
                        {
                            model.AvailableCountries.Add(new SelectListItem()
                            {
                                Text = c.GetLocalized(x => x.Name),
                                Value = c.Id.ToString()
                            });
                        }
                    }
                    else
                    {
                        model.AvailableCountries.Add(new SelectListItem()
                        {
                            Text = c.GetLocalized(x => x.Name),
                            Value = c.Id.ToString(),
                            Selected = c.Id == model.CountryId
                        });

                    }

                }

Kind Regards.
9 years ago
I'm new to MVC/.net so still struggling with following the code fully.

I've added this on a NOP Version 3.5 and whilst it selects UK successfully as the default Country it does not automatically populate the State list with the Counties(UK State list), have I missed something or is the original code not designed to enable this to fire?

Regards,
Renners.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.