How to restore deleted country under admin...
How to restore deleted country under admin...
Because we originally were only shipping to the US and Canada, we deleted all the other countries under the Administration/Configure/Regions/Countries. Now we would like to restore many. Is there a file I can restore so that the country list will return to its default list (along with the address formats)? It would have been nicer if we could have just selected which countries we wanted to include in our shipping region rather than having to delete ones we did not want to include. We are using AbleCommerce 7.0.3 build 12458.
Re: How to restore deleted country under admin...
Try this code by creating a file in Install folder like 'RestoreCountries.aspx' and placing this code in that file then navigate to the this page e-g 'http://www.ablecommerce/Install/RestoreCountries.aspx' and running the script it will restore default countries.
You can also use attachment files.
Thanks
Code: Select all
<%@ Page Language="C#" AutoEventWireup="true"%>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Xml" %>
<%@ Import Namespace="CommerceBuilder.Data" %>
<%@ Import Namespace="CommerceBuilder.Utility" %>
<%@ Import Namespace="CommerceBuilder.Configuration" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Register Assembly="CommerceBuilder.Web" Namespace="CommerceBuilder.Web.UI.WebControls" TagPrefix="cb" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
</head>
<body>
<script runat="server">
protected void RestoreButton_Click(object sender, EventArgs e)
{
CreateCountries(CountryDefaults.SelectedIndex == 0);
}
protected void CreateCountries(bool northAmericaOnly)
{
XmlDocument countryData = new XmlDocument();
countryData.Load(Server.MapPath("~/Install/countries.xml"));
if (northAmericaOnly)
{
XmlNode countryNode = countryData.DocumentElement.SelectSingleNode("Country[@Code=\"CA\"]");
if (countryNode != null) AddCountry(countryNode);
countryNode = countryData.DocumentElement.SelectSingleNode("Country[@Code=\"MX\"]");
if (countryNode != null) AddCountry(countryNode);
countryNode = countryData.DocumentElement.SelectSingleNode("Country[@Code=\"US\"]");
if (countryNode != null) AddCountry(countryNode);
}
else
{
XmlNodeList countries = countryData.DocumentElement.SelectNodes("Country");
foreach (XmlNode countryNode in countries)
{
AddCountry(countryNode);
}
}
}
protected void AddCountry(XmlNode countryNode)
{
CommerceBuilder.Shipping.Country country = new CommerceBuilder.Shipping.Country();
country.CountryCode = Server.UrlDecode(XmlUtility.GetAttributeValue(countryNode, "Code", string.Empty));
country.Name = Server.UrlDecode(XmlUtility.GetAttributeValue(countryNode, "Name", string.Empty));
if (!string.IsNullOrEmpty(country.CountryCode) && !string.IsNullOrEmpty(country.Name))
{
country.AddressFormat = Server.UrlDecode(XmlUtility.GetElementValue(countryNode, "AddressFormat", string.Empty));
XmlElement provinceNodes = XmlUtility.GetElement(countryNode, "Provinces", false);
if (provinceNodes != null)
{
foreach (XmlNode provinceNode in provinceNodes.ChildNodes)
{
Province province = new Province();
province.Name = Server.UrlDecode(XmlUtility.GetAttributeValue(provinceNode, "Name", string.Empty));
province.ProvinceCode = Server.UrlDecode(XmlUtility.GetAttributeValue(provinceNode, "Abbreviation", string.Empty));
if (province.Name != string.Empty)
{
country.Provinces.Add(province);
}
}
}
country.Save();
}
}
</script>
<form id="form1" runat="server">
<div>
<table>
<tr>
<th align="right" nowrap>
<asp:Label ID="CountryDefaultsLabel" runat="server" Text="Countries:" EnableViewState="false"></asp:Label>
</th>
<td align="left">
<asp:DropDownList ID="CountryDefaults" runat="server">
<asp:ListItem Value="NorthAmerica" Text="Canada, Mexico, and United States"></asp:ListItem>
<asp:ListItem Value="All" Text="All Countries" Selected="true"></asp:ListItem>
</asp:DropDownList>
<asp:Button ID="RestoreButton" runat="server" Text="Restore" OnClick="RestoreButton_Click" />
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
Thanks
hope this helps!
__________________
s_ismail
AbleCommerce Customization
Free Plugins and Add-Ons
AbleCommerce Plugins and Add-Ons
Plugables Blog
__________________
s_ismail
AbleCommerce Customization
Free Plugins and Add-Ons
AbleCommerce Plugins and Add-Ons
Plugables Blog
Re: How to restore deleted country under admin...
thanks. I was having a bit of trouble with this, but I got it to work. thank you!