logo
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
itmtrust  
#1 Posted : Friday, November 25, 2016 10:44:31 AM(UTC)
itmtrust

Rank: Newbie

Groups: Registered
Joined: 11/25/2016(UTC)
Posts: 1
South Africa
Location: Cape Town

Hi

Does there exist a method or app to import bulk products into the database?

I see that the products export as xml file but I would want to import products into articles in simple format and then configure models once they are imported.
leedavi  
#2 Posted : Saturday, November 26, 2016 11:46:09 AM(UTC)
leedavi

Rank: Administration

Groups: Registered, Administrators
Joined: 11/6/2016(UTC)
Posts: 323
United Kingdom
Location: France

Was thanked: 28 time(s) in 28 post(s)
You can use excel and this project

https://github.com/Fabio...gi/NBrightBuyExcelImport

Althought it's setup for a perticular format and often people have to adjust it to meet their requirments.

I've also used this project for a client in a very simple format. I altered this code to do that.

with a CSV file of:

Manufacturer;txtproductref;name;txtunitcost;summary;description
;Al777;12 Volt veiliheidstrafo tbv LED verlichting;145;100 watt, 12 volt, met aan/uit schakelaar op de trafo;
;Mu674;24 volt power pack;74;0;24 volt power pack 3 A / 24V AC supply

I changed the "Import.ascx.cs" function "public string ListToNbrightBuyXml(CsvFileReader reader)" code to this:


Code:



        private void DoImport(NBrightInfo nbi)
        {
            //check parameters

            var csvDelimiter = nbi.GetXmlProperty("genxml/textbox/csvdelimiter");
            var categoryLevelNumber = Convert.ToInt32(nbi.GetXmlProperty("genxml/textbox/categorylevelnumber"));

            var csvFile = StoreSettings.Current.FolderTempMapPath + "\\" + nbi.GetXmlProperty("genxml/hidden/hiddatafile");
            if (System.IO.File.Exists(csvFile))
            {

                var reader = new CsvFileReader(csvFile);
                reader.Delimiter = ';';
                reader.Quote = '"';

                var xmlToImport = ListToNbrightBuyXml(reader);

            }

        }

        public string ListToNbrightBuyXml(CsvFileReader reader)
        {
            // open template file
            var templatePath = StoreSettings.Current.FolderUploadsMapPath;
            var PRDxmltemplatepath = templatePath.Substring(0, templatePath.IndexOf("Portals")) + @"DesktopModules\NBright\NBrightBuyExcelImport\Templates\PRD_template.xml";
            var PRD_MODEL_xmltemplatepath = templatePath.Substring(0, templatePath.IndexOf("Portals")) + @"DesktopModules\NBright\NBrightBuyExcelImport\Templates\PRD_MODEL_template.xml";
            var PRDLANGxmltemplatepath = templatePath.Substring(0, templatePath.IndexOf("Portals")) + @"DesktopModules\NBright\NBrightBuyExcelImport\Templates\PRDLANG_template.xml";
            var PRDLANG_MODEL_xmltemplatepath = templatePath.Substring(0, templatePath.IndexOf("Portals")) + @"DesktopModules\NBright\NBrightBuyExcelImport\Templates\PRDLANG_MODEL_template.xml";

            var CATEGORYxmltemplatepath = templatePath.Substring(0, templatePath.IndexOf("Portals")) + @"DesktopModules\NBright\NBrightBuyExcelImport\Templates\CATEGORY_template.xml";
            var CATEGORYLANGxmltemplatepath = templatePath.Substring(0, templatePath.IndexOf("Portals")) + @"DesktopModules\NBright\NBrightBuyExcelImport\Templates\CATEGORYLANG_template.xml";
            var CATXREFxmltemplatepath = templatePath.Substring(0, templatePath.IndexOf("Portals")) + @"DesktopModules\NBright\NBrightBuyExcelImport\Templates\CATXREF_template.xml";

            string PRDxmltemplate; string PRDLANGxmltemplate; string CATEGORYxmltemplate; string CATEGORYLANGxmltemplate; string PRD_MODEL_xmltemplate;
            string PRDLANG_MODEL_xmltemplate; string CATXREFxmltemplate;
            // var xmlTemplateFile = new XmlDocument();
            if (System.IO.File.Exists(PRDxmltemplatepath)) { PRDxmltemplate = File.ReadAllText(PRDxmltemplatepath, System.Text.Encoding.GetEncoding("utf-8")); }
            else { PRDxmltemplate = ""; }
            if (System.IO.File.Exists(PRDLANGxmltemplatepath)) { PRDLANGxmltemplate = File.ReadAllText(PRDLANGxmltemplatepath, System.Text.Encoding.GetEncoding("utf-8")); }
            else { PRDLANGxmltemplate = ""; }

            if (System.IO.File.Exists(PRD_MODEL_xmltemplatepath)) { PRD_MODEL_xmltemplate = File.ReadAllText(PRD_MODEL_xmltemplatepath, System.Text.Encoding.GetEncoding("utf-8")); }
            else { PRD_MODEL_xmltemplate = ""; }
            if (System.IO.File.Exists(PRDLANG_MODEL_xmltemplatepath)) { PRDLANG_MODEL_xmltemplate = File.ReadAllText(PRDLANG_MODEL_xmltemplatepath, System.Text.Encoding.GetEncoding("utf-8")); }
            else { PRDLANG_MODEL_xmltemplate = ""; }

            if (System.IO.File.Exists(CATEGORYxmltemplatepath)) { CATEGORYxmltemplate = File.ReadAllText(CATEGORYxmltemplatepath, System.Text.Encoding.GetEncoding("utf-8")); }
            else { CATEGORYxmltemplate = ""; }
            if (System.IO.File.Exists(CATEGORYLANGxmltemplatepath)) { CATEGORYLANGxmltemplate = File.ReadAllText(CATEGORYLANGxmltemplatepath, System.Text.Encoding.GetEncoding("utf-8")); }
            else { CATEGORYLANGxmltemplate = ""; }
            if (System.IO.File.Exists(CATXREFxmltemplatepath)) { CATXREFxmltemplate = File.ReadAllText(CATXREFxmltemplatepath, System.Text.Encoding.GetEncoding("utf-8")); }
            else { CATXREFxmltemplate = ""; }


            var langList = DnnUtils.GetCultureCodeList(PortalId);
            var id = 1000;


            string finalXML = @"<root>";

            string articleref = ""; string modelRef = ""; string modelID = ""; string image1name = ""; string currentPRD = ""; string currentPRDMODEL = "";
            string currentPRDLANG = ""; string currentPRDLANGMODEL = "";

            // read data list into memory so we can read forward, to check for change of article.
            var readcolumns = new List<string>();
            var readList = new List<List<string>>();
            while (reader.ReadRow(readcolumns))
            {
                var savecolumns = new List<String>();
                // need a object not a ref
                foreach (var c in readcolumns)
                {
                    savecolumns.Add(c);
                }
                readList.Add(savecolumns);
            }

            var headers = new Dictionary<string,int>();
            var lp = 1;
            var beforearticleref = "-1";
            var nextarticleref = "-1";
            foreach (var columns in readList)
            {
                if (lp == 1)
                {
                    // first row, get names of fields from header of CSV
                    var lp2 = 0;
                    foreach (var h in columns)
                    {
                        var key = h.ToLower();
                        if (headers.ContainsKey(key)) key = h.ToLower() + lp2;
                        headers.Add(key,lp2);
                        lp2 += 1;
                    }
                }
                else
                {

                    /////////////////////////////////////////////////////////
                    /////////////////// PRD ////////////////////////////////
                    /////////////////// PRD ////////////////////////////////

                    var prdData = new ProductData(-1,Utils.GetCurrentCulture());
                    var currentlang = Utils.GetCurrentCulture();

                    prdData.DataRecord.PortalId = -1;
                    prdData.DataLangRecord.PortalId = -1;

                    // TYCO IMPORT Alternatief-minimum-to-import.csv & Producten Pasdedeux6nov2016.csv
                    prdData.DataRecord.SetXmlProperty("genxml/textbox/txtproductref", GetColumnValue(columns, headers, "txtproductref", id.ToString("D5")));
                    prdData.DataRecord.SetXmlProperty("genxml/checkbox/chkishidden", "False");

                    prdData.DataRecord.SetXmlProperty("genxml/models/genxml[1]/textbox", ""); // create node
                    prdData.DataRecord.SetXmlProperty("genxml/models/genxml[1]/textbox/txtmodelref", GetColumnValue(columns, headers, "txtproductref", id.ToString("D5"))); // create node
                    prdData.DataRecord.SetXmlPropertyDouble("genxml/models/genxml[1]/textbox/txtunitcost", GetColumnValue(columns, headers, "txtunitcost", "0"));

                    prdData.DataLangRecord.SetXmlProperty("genxml/textbox/txtproductname", GetColumnValue(columns, headers, "name_" + currentlang, GetColumnValue(columns, headers, "name")));
                    prdData.DataLangRecord.SetXmlProperty("genxml/textbox/txtsummary", GetColumnValue(columns, headers, "summary_" + currentlang, GetColumnValue(columns, headers, "summary")));
                    prdData.DataLangRecord.SetXmlProperty("genxml/edt", ""); // create node
                    prdData.DataLangRecord.SetXmlProperty("genxml/edt/description", GetColumnValue(columns, headers, "description_" + currentlang, GetColumnValue(columns, headers, "description")));

                    prdData.DataLangRecord.SetXmlProperty("genxml/models/genxml[1]/textbox", ""); // create node
                    prdData.DataLangRecord.SetXmlProperty("genxml/models/genxml[1]/textbox/txtmodelname", GetColumnValue(columns, headers, "name_" + currentlang, GetColumnValue(columns, headers, "name")));

                    // do image
                    var imagepath = GetColumnValue(columns, headers, "imagepath", "");
                    if (imagepath != "")
                    {
                        var fname = Path.GetFileName(imagepath);
                        var newimagepath = StoreSettings.Current.FolderImagesMapPath + "\\" + fname;
                        var newimageurl = StoreSettings.Current.FolderImages + "/" + fname;
                        prdData.DataRecord.SetXmlProperty("genxml/imgs", ""); // create node
                        prdData.DataRecord.SetXmlProperty("genxml/imgs/genxml", ""); // create node
                        prdData.DataRecord.SetXmlProperty("genxml/imgs/genxml[1]/hidden", ""); // create node
                        prdData.DataRecord.SetXmlProperty("genxml/imgs/genxml[1]/hidden/imagepath", newimagepath); // create node
                        prdData.DataRecord.SetXmlProperty("genxml/imgs/genxml[1]/hidden/imageurl", newimageurl); // create node
                    }


                    prdData.Save();

                    prdData.Validate();

                    id += 1;

                }

                lp += 1;
            }

            finalXML += @"</root>";
            return finalXML;
        }// end function


leedavi  
#3 Posted : Saturday, November 26, 2016 11:49:31 AM(UTC)
leedavi

Rank: Administration

Groups: Registered, Administrators
Joined: 11/6/2016(UTC)
Posts: 323
United Kingdom
Location: France

Was thanked: 28 time(s) in 28 post(s)
I also used this class, created by Jonathan Wood.

https://www.codeproject....ting-csv-files-in-csharp

manfred-hain  
#4 Posted : Wednesday, December 14, 2016 6:17:45 PM(UTC)
manfred-hain

Rank: Newbie

Groups: Registered
Joined: 11/24/2016(UTC)
Posts: 1
South Africa
Location: PLZ

I am uncertain regarding the GetColumnValue() class?

e.g. line 113: .... GetColumnValue(columns, headers, "txtproductref", id.ToString("D5"))...

Have I missed / overlooked something?
Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Powered by YAF.NET | YAF.NET © 2003-2019, Yet Another Forum.NET
This page was generated in 0.064 seconds.