Note: This documentation is for the preview version of the upcoming release of CMS 12/Commerce 14/Search & Navigation 14. Features included here might not be complete, and might be changed before becoming available in the public release. This documentation is provided for evaluation purposes only.
This topic explains how to configure countries and regions in Optimizely Commerce.
Countries and regions are used when configuring markets and tax jurisdictions, and can also be used on the front-end when dealing with order addresses. On install, an extensive list of countries is created.
Classes in this topic are in the following namespaces:
- Mediachase.Commerce.Orders
- Mediachase.Commerce.Orders.Dto
- Mediachase.Commerce.Orders.Managers
Working with countries and regions
Creating countries and regions
var dto = new CountryDto(); var countryRow = dto.Country.NewCountryRow(); countryRow.Name = "Country Name"; countryRow.Code = "AAA"; //Three digit country code. countryRow.Ordering = 0; countryRow.Visible = true; if (countryRow.RowState == DataRowState.Detached) dto.Country.Rows.Add(countryRow); dto.EnforceConstraints = false; var region = dto.StateProvince.NewStateProvinceRow(); region.Name = "My Region"; region.Ordering = 0; region.Visible = true; region.CountryId = dto.Country[0].CountryId; if (region.RowState == DataRowState.Detached) dto.StateProvince.Rows.Add(region); dto.EnforceConstraints = true; CountryManager.SaveCountry(dto);
Updating countries and regions
var dto = CountryManager.GetCountry("USA", true); var countryRow = dto.Country[0]; countryRow.Ordering = 20; countryRow.Visible = false; var ca = countryRow.GetStateProvinceRows().FirstOrDefault(x => x.Name.Equals("California")); ca.Ordering = 5; CountryManager.SaveCountry(dto);
Deleting countries and regions
var dto = CountryManager.GetCountry("USA", true); var countryRow = dto.Country[0]; countryRow.Delete(); CountryManager.SaveCountry(dto);
Related topics
Do you find this information helpful? Please log in to provide feedback.
Last updated: Jul 02, 2021