Countries and regions
Describes how to configure countries and regions in Optimizely Commerce Connect.
Use countries and regions when configuring markets and tax jurisdictions, or on the front end when working with orders. Installation creates an extensive list of countries.
Classes in this topic are in the following namespaces:
Mediachase.Commerce.OrdersMediachase.Commerce.Orders.DtoMediachase.Commerce.Orders.Managers
Create countries and regions
The following example creates a country and an associated region:
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);Update countries and regions
The following example updates the ordering and visibility of a country and adjusts the ordering of one of its 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);Delete countries and regions
The following example deletes a country:
var dto = CountryManager.GetCountry("USA", true);
var countryRow = dto.Country[0];
countryRow.Delete();
CountryManager.SaveCountry(dto);Updated 27 days ago
