How to restore deleted country under admin...

For general questions and discussions specific to the AbleCommerce 7.0 Asp.Net product.
Post Reply
snap624
Lieutenant (LT)
Lieutenant (LT)
Posts: 58
Joined: Mon Jan 19, 2009 2:53 pm

How to restore deleted country under admin...

Post by snap624 » Thu May 20, 2010 1:19 am

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.

User avatar
s_ismail
Commander (CMDR)
Commander (CMDR)
Posts: 162
Joined: Mon Nov 09, 2009 12:20 am
Contact:

Re: How to restore deleted country under admin...

Post by s_ismail » Thu May 20, 2010 4:22 am

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.

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>
You can also use attachment files.
Thanks

snap624
Lieutenant (LT)
Lieutenant (LT)
Posts: 58
Joined: Mon Jan 19, 2009 2:53 pm

Re: How to restore deleted country under admin...

Post by snap624 » Wed Jun 02, 2010 12:41 pm

thanks. I was having a bit of trouble with this, but I got it to work. thank you!

Post Reply