/// <summary>
        ///
        /// </summary>
        /// <param name="portalfinfo"></param>
        /// <returns></returns>
        public override string DoWork()
        {
            try
            {
                var objCtrl = new NBrightBuyController();

                // the sceduler runs at host level, we therefore need to loop through ALL portals to process data at a portal level.
                var portalList = NBrightDNN.DnnUtils.GetAllPortals();
                foreach (var portal in portalList)
                {
                    // check if we have NBS in this portal by looking for default settings.
                    var nbssetting = objCtrl.GetByGuidKey(portal.PortalID, -1, "SETTINGS", "NBrightBuySettings");
                    if (nbssetting != null)
                    {
                        var storeSettings = new StoreSettings(portal.PortalID);
                        var pluginData    = new PluginData(portal.PortalID); // get plugin data to see if this scheduler is active on this portal
                        var plugin        = pluginData.GetPluginByCtrl("dnnsearchindex");
                        if (plugin != null && plugin.GetXmlPropertyBool("genxml/checkbox/active"))
                        {
                            // The NBS scheduler is normally set to run hourly, therefore if we only want a process to run daily we need the logic this function.
                            // To to this we keep a last run flag on the sceduler settings
                            var setting = objCtrl.GetByGuidKey(portal.PortalID, -1, "DNNIDXSCHEDULER", "DNNIDXSCHEDULER");
                            if (setting == null)
                            {
                                setting          = new NBrightInfo(true);
                                setting.ItemID   = -1;
                                setting.PortalId = portal.PortalID;
                                setting.TypeCode = "DNNIDXSCHEDULER";
                                setting.GUIDKey  = "DNNIDXSCHEDULER";
                                setting.ModuleId = -1;
                                setting.XMLData  = "<genxml></genxml>";
                            }


                            var lastrun     = setting.GetXmlPropertyRaw("genxml/lastrun");
                            var lastrundate = DateTime.Now.AddYears(-99);
                            if (Utils.IsDate(lastrun))
                            {
                                lastrundate = Convert.ToDateTime(lastrun);
                            }

                            var rtnmsg = DoProductIdx(portal, lastrundate, storeSettings.DebugMode);
                            setting.SetXmlProperty("genxml/lastrun", DateTime.Now.ToString("s"), TypeCode.DateTime);
                            objCtrl.Update(setting);
                            if (rtnmsg != "")
                            {
                                return(rtnmsg);
                            }
                        }
                    }
                }

                return(" - NBS-DNNIDX scheduler OK ");
            }
            catch (Exception ex)
            {
                return(" - NBS-DNNIDX scheduler FAIL: " + ex.ToString() + " : ");
            }
        }
Esempio n. 2
0
        private static void RecalculateSummary(HttpContext context)
        {
            var objCtrl = new NBrightBuyController();

            var currentcart = new CartData(PortalSettings.Current.PortalId);
            var ajaxInfo    = NBrightBuyUtils.GetAjaxInfo(context, true);
            var shipoption  = currentcart.GetShippingOption(); // ship option already set in address update.

            currentcart.AddExtraInfo(ajaxInfo);
            currentcart.SetShippingOption(shipoption);
            currentcart.PurchaseInfo.SetXmlProperty("genxml/currentcartstage", "cartsummary"); // (Legacy) we need to set this so the cart calcs shipping
            currentcart.PurchaseInfo.SetXmlProperty("genxml/extrainfo/genxml/radiobuttonlist/shippingprovider", ajaxInfo.GetXmlProperty("genxml/radiobuttonlist/shippingprovider"));

            var shipref     = ajaxInfo.GetXmlProperty("genxml/radiobuttonlist/shippingprovider");
            var displayanme = "";
            var shipInfo    = objCtrl.GetByGuidKey(PortalSettings.Current.PortalId, -1, "SHIPPING", shipref);

            if (shipInfo != null)
            {
                var shipprov = ShippingInterface.Instance(shipref);
                if (shipprov != null)
                {
                    displayanme = shipprov.Name();
                }
            }
            if (displayanme == "")
            {
                displayanme = shipref;
            }
            currentcart.PurchaseInfo.SetXmlProperty("genxml/extrainfo/genxml/hidden/shippingdisplayanme", displayanme);

            currentcart.Lang = ajaxInfo.Lang;  // set lang so we can send emails in same language the order was made in.

            currentcart.Save(StoreSettings.Current.DebugMode, true);
        }
Esempio n. 3
0
        public IEncodedString QtyPromoDescription(int productId, string qtypromoref = "")
        {
            var qtydescritpion = "";
            var objCtrl        = new NBrightBuyController();
            var prodData       = new ProductData(productId, Utils.GetCurrentCulture());

            if (qtypromoref != "")
            {
                var qtypromo = objCtrl.GetByGuidKey(PortalSettings.Current.PortalId, -2, "QTYPROMO", qtypromoref);
                if (bulkBuyOn(prodData, qtypromo))
                {
                    var qtyInfo = objCtrl.GetData(qtypromo.ItemID, "QTYPROMOLANG", Utils.GetCurrentCulture());
                    qtydescritpion = qtyInfo.GetXmlProperty("genxml/lang/genxml/textbox/description");
                }
            }
            else
            {
                var qtypromolist = objCtrl.GetList(PortalSettings.Current.PortalId, -2, "QTYPROMO");
                foreach (var q in qtypromolist)
                {
                    if (bulkBuyOn(prodData, q))
                    {
                        var qtyInfo = objCtrl.GetData(q.ItemID, "QTYPROMOLANG", Utils.GetCurrentCulture());
                        qtydescritpion = qtyInfo.GetXmlProperty("genxml/lang/genxml/textbox/description");
                        break;
                    }
                }
            }

            return(new RawString(qtydescritpion));
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="cartInfo"></param>
        /// <returns></returns>
        public override NBrightInfo CalculateShipping(NBrightInfo cartInfo)
        {
            // return zero if we have invalid data
            cartInfo.SetXmlPropertyDouble("genxml/shippingcost", "0");
            cartInfo.SetXmlPropertyDouble("genxml/shippingcostTVA", "0");
            cartInfo.SetXmlPropertyDouble("genxml/shippingdealercost", "0");

            var modCtrl = new NBrightBuyController();
            var info    = modCtrl.GetByGuidKey(PortalSettings.Current.PortalId, -1, "SHIPPING", Shippingkey);

            if (info == null)
            {
                return(cartInfo);
            }


            double shippingcost = 10;

            if (cartInfo.GetXmlPropertyInt("genxml/OS_ShippingProviderlistidx") == 1)
            {
                shippingcost = 99.99;
            }

            var shippingdealercost = shippingcost;

            cartInfo.SetXmlPropertyDouble("genxml/shippingcostTVA", "0");
            cartInfo.SetXmlPropertyDouble("genxml/shippingcost", shippingcost);
            cartInfo.SetXmlPropertyDouble("genxml/shippingdealercost", shippingdealercost);

            return(cartInfo);
        }
Esempio n. 5
0
        public IEncodedString HasQtyPromo(int productId, string qtypromoref = "")
        {
            var objCtrl  = new NBrightBuyController();
            var prodData = new ProductData(productId, Utils.GetCurrentCulture());

            if (qtypromoref != "")
            {
                var qtypromo = objCtrl.GetByGuidKey(PortalSettings.Current.PortalId, -2, "QTYPROMO", qtypromoref);
                if (bulkBuyOn(prodData, qtypromo))
                {
                    return(new RawString("true"));
                }
            }
            else
            {
                var qtypromolist = objCtrl.GetList(PortalSettings.Current.PortalId, -2, "QTYPROMO");
                foreach (var q in qtypromolist)
                {
                    if (bulkBuyOn(prodData, q))
                    {
                        return(new RawString("true"));
                    }
                }
            }
            return(new RawString("false"));
        }
Esempio n. 6
0
        public override NBrightInfo CalculateShipping(NBrightInfo cartInfo)
        {
            cartInfo.SetXmlPropertyDouble("genxml/shippingcost", "0");
            cartInfo.SetXmlPropertyDouble("genxml/shippingcostTVA", "0");
            cartInfo.SetXmlPropertyDouble("genxml/shippingdealercost", "0");

            NBrightBuyController nbCtrl = new NBrightBuyController();
            NBrightInfo          nbInfo = nbCtrl.GetByGuidKey(PortalSettings.Current.PortalId, -1, "SHIPPING", Shippingkey);

            if (nbInfo == null)
            {
                return(cartInfo);
            }


            double shippingcost = 0;

            if (cartInfo.GetXmlPropertyInt("genxml/OS_AllShippinglistidx") == 1)
            {
                shippingcost = 99.99;
            }

            NBrightInfo shippInfo = nbCtrl.GetByGuidKey(PortalSettings.Current.PortalId, -1, "SHIPPING", "OS_AllShipping");

            if (Merchant.IsEnable)
            {
                shippingcost = Merchant.FamiCost;

                if (cartInfo.GetXmlPropertyDouble("genxml/appliedsubtotal") >= Merchant.FreeCost)
                {
                    shippingcost = 0;
                }
            }
            var shippingdealercost = shippingcost;

            cartInfo.SetXmlPropertyDouble("genxml/shippingcostTVA", "0");
            cartInfo.SetXmlPropertyDouble("genxml/shippingcost", shippingcost);
            cartInfo.SetXmlPropertyDouble("genxml/shippingdealercost", shippingdealercost);

            return(cartInfo);
        }
        private void PopulateData(String key)
        {
            var modCtrl = new NBrightBuyController();

            Info = modCtrl.GetByGuidKey(PortalSettings.Current.PortalId, -1, "PROMOCODES", key);
            if (Info == null)
            {
                Info          = new NBrightInfo(true);
                Info.GUIDKey  = key;
                Info.TypeCode = "PROMOCODES";
                Info.ModuleId = -1;
                Info.PortalId = PortalSettings.Current.PortalId;
            }
            _discountcodesList = GetRuleList();
        }
        protected override void OnInit(EventArgs e)
        {
            //Remove any cache for the module, we don't want any cache in/after the BO editing.
            NBrightBuyUtils.RemoveModCache(ModuleId);

            // add required controls.
            RpData              = new Repeater();
            RpData.ItemCommand += CtrlItemCommand;

            this.Controls.Add(RpData);

            //set default Data controller
            ModCtrl = new NBrightBuyController();


            #region "Get all Settings for module"
            //get Model Level Settings
            ModSettings = new ModSettings(ModuleId, Settings);

            #endregion

            var strTemplate = "";
            if (!String.IsNullOrEmpty(CtrlPluginPath))
            {
                //search plugin path for template
                strTemplate = NBrightBuyUtils.GetTemplateData(CtrlTypeCode + "_Settings.html", CtrlPluginPath, "config", ModSettings.Settings());
            }
            if (strTemplate == "")
            {
                // add themefolder to settings, incase module has independant theme.
                strTemplate = ModCtrl.GetTemplateData(ModSettings, CtrlTypeCode + "_Settings.html", Utils.GetCurrentCulture(), StoreSettings.Current.DebugMode);
            }
            if (strTemplate != "")
            {
                RpData.ItemTemplate = NBrightBuyUtils.GetGenXmlTemplate(strTemplate, ModSettings.Settings(), PortalSettings.HomeDirectory);
            }

            //add template provider to NBright Templating
            NBrightCore.providers.GenXProviderManager.AddProvider("NBrightBuy,Nevoweb.DNN.NBrightBuy.render.GenXmlTemplateExt");
            var pInfo = ModCtrl.GetByGuidKey(PortalId, -1, "PROVIDERS", "NBrightTempalteProviders");
            if (pInfo != null)
            {
                NBrightCore.providers.GenXProviderManager.AddProvider(pInfo.XMLDoc);
            }


            base.OnInit(e);
        }
        private String SaveData(HttpContext context)
        {
            var objCtrl = new NBrightBuyController();

            //get uploaded params
            var ajaxInfo = NBrightBuyUtils.GetAjaxFields(context);


            var guidkey  = ajaxInfo.GetXmlProperty("genxml/hidden/guidkey");
            var typeCode = ajaxInfo.GetXmlProperty("genxml/hidden/typecode");
            var editlang = ajaxInfo.GetXmlProperty("genxml/hidden/editlang");

            if (editlang == "")
            {
                editlang = _lang;
            }


            // get data record with language
            var obj = objCtrl.GetByGuidKey(PortalSettings.Current.PortalId, -2, typeCode, guidkey);

            if (obj != null)
            {
                // get DB record
                var nbi = objCtrl.Get(obj.ItemID);
                if (nbi != null)
                {
                    // get data passed back by ajax
                    var strIn = HttpUtility.UrlDecode(Utils.RequestParam(context, "inputxml"));
                    // update record with ajax data
                    nbi.UpdateAjax(strIn);
                    if (nbi.GUIDKey == "")
                    {
                        nbi.GUIDKey = typeCode;
                    }
                    objCtrl.Update(nbi);

                    // do langauge record
                    var nbi2 = objCtrl.GetDataLang(obj.ItemID, editlang);
                    nbi2.UpdateAjax(strIn);
                    objCtrl.Update(nbi2);

                    DataCache.ClearCache(); // clear ALL cache.
                }
            }
            return("");
        }
Esempio n. 10
0
        public static void PluginSave(HttpContext context)
        {
            if (NBrightBuyUtils.CheckRights())
            {
                var ajaxInfo = NBrightBuyUtils.GetAjaxFields(context);
                var itemid   = ajaxInfo.GetXmlProperty("genxml/hidden/itemid");
                if (Utils.IsNumeric(itemid))
                {
                    var objCtrl      = new NBrightBuyController();
                    var info         = objCtrl.GetData(Convert.ToInt32(itemid));
                    var pluginRecord = new PluginRecord(info);
                    var modelXml     = Utils.UnCode(ajaxInfo.GetXmlProperty("genxml/hidden/xmlupdatemodeldata"));

                    ajaxInfo.RemoveXmlNode("genxml/hidden/xmlupdatemodeldata");
                    pluginRecord.Info().XMLData = ajaxInfo.XMLData;

                    // check for unique ctrl ref
                    var ctrlref  = pluginRecord.Info().GetXmlProperty("genxml/textbox/ctrl");
                    var ctrltest = objCtrl.GetByGuidKey(PortalSettings.Current.PortalId, -1, "PLUGIN", ctrlref);
                    if (ctrltest != null)
                    {
                        if (ctrltest.ItemID != pluginRecord.Info().ItemID)
                        {
                            pluginRecord.Info().SetXmlProperty("genxml/textbox/ctrl", pluginRecord.Info().GetXmlProperty("genxml/textbox/ctrl") + Utils.GetUniqueKey());
                        }
                    }

                    // make sure index is in correct format, (FLOAT) for SQL
                    pluginRecord.Info().SetXmlProperty("genxml/hidden/index", (pluginRecord.Info().GetXmlPropertyInt("genxml/hidden/index").ToString()), TypeCode.Double);
                    pluginRecord.Info().RemoveXmlNode("genxml/hidden/itemid");
                    pluginRecord.Info().RemoveXmlNode("genxml/hidden/editlanguage");
                    pluginRecord.Info().RemoveXmlNode("genxml/hidden/uilang1");
                    pluginRecord.Info().GUIDKey = pluginRecord.Info().GetXmlProperty("genxml/textbox/ctrl");

                    pluginRecord.UpdateModels(modelXml, Utils.GetCurrentCulture());
                    objCtrl.Update(pluginRecord.Info());

                    // remove save GetData cache
                    DataCache.ClearCache();

                    //load entity typecode to DB idx settings.
                    NBrightBuyUtils.RegisterEnityTypeToDataBase();
                }
            }
        }
Esempio n. 11
0
        public override NBrightInfo UpdatePercentUsage(int portalId, int userId, NBrightInfo purchaseInfo)
        {
            var discountcode = purchaseInfo.GetXmlProperty("genxml/extrainfo/genxml/textbox/promocode");

            if (!purchaseInfo.GetXmlPropertyBool("genxml/discountprocessed"))
            {
                if (userId > 0)
                {
                    if (discountcode == "")
                    {
                        return(purchaseInfo);
                    }
                    var clientData = new ClientData(portalId, userId);
                    if (clientData.DiscountCodes.Count > 0)
                    {
                        var list = clientData.DiscountCodes;
                        foreach (var d in list)
                        {
                            if (d.GetXmlProperty("genxml/textbox/coderef").ToLower() == discountcode.ToLower())
                            {
                                var usageleft = d.GetXmlPropertyDouble("genxml/textbox/usageleft");
                                var used      = d.GetXmlPropertyDouble("genxml/textbox/used");
                                d.SetXmlPropertyDouble("genxml/textbox/usageleft", (usageleft - 1));
                                d.SetXmlPropertyDouble("genxml/textbox/used", (used + 1));
                            }
                        }
                        clientData.UpdateDiscountCodeList(list);
                        clientData.Save();
                        purchaseInfo.SetXmlProperty("genxml/discountprocessed", "True");
                    }
                }

                var objCtrl = new NBrightBuyController();
                var dis     = objCtrl.GetByGuidKey(portalId, -1, "DISCOUNTCODE", discountcode);
                if (dis != null)
                {
                    var usage = dis.GetXmlPropertyDouble("genxml/textbox/usage");
                    dis.SetXmlPropertyDouble("genxml/textbox/usage", (usage + 1));
                    objCtrl.Update(dis);
                    purchaseInfo.SetXmlProperty("genxml/discountprocessed", "True");
                }
            }

            return(purchaseInfo);
        }
        private String GetData(HttpContext context, bool clearCache = false)
        {
            var objCtrl = new NBrightBuyController();
            var strOut  = "";
            //get uploaded params
            var ajaxInfo = NBrightBuyUtils.GetAjaxFields(context);

            var guidkey  = ajaxInfo.GetXmlProperty("genxml/hidden/guidkey");
            var typeCode = ajaxInfo.GetXmlProperty("genxml/hidden/typecode");
            var moduleid = ajaxInfo.GetXmlProperty("genxml/hidden/moduleid");
            var editlang = ajaxInfo.GetXmlProperty("genxml/hidden/editlang");

            if (editlang == "")
            {
                editlang = _lang;
            }

            if (!Utils.IsNumeric(moduleid))
            {
                moduleid = "-2";                             // use moduleid -2 for razor
            }
            if (clearCache)
            {
                NBrightBuyUtils.RemoveModCache(Convert.ToInt32(moduleid));
            }

            var templateControl = "/DesktopModules/NBright/NBrightBuyOpenUrlRewriter";

            // get data record with language
            var obj = objCtrl.GetByGuidKey(PortalSettings.Current.PortalId, Convert.ToInt32(moduleid), typeCode, guidkey);

            if (obj == null)
            {
                var itemId = AddNew(moduleid, typeCode);
                obj = objCtrl.Get(itemId);
            }
            var objData = objCtrl.GetData(obj.ItemID, typeCode + "LANG", editlang);

            //strOut = NBrightBuyUtils.RazorTemplRender(typeCode.ToLower() + "fields.cshtml", Convert.ToInt32(moduleid), _lang + guidkey + editlang, objData, templateControl, "config", editlang, StoreSettings.Current.Settings());

            return(strOut);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="cartInfo"></param>
        /// <returns></returns>
        public override NBrightInfo CalculateShipping(NBrightInfo cartInfo)
        {
            // return zero if we have invalid data
            cartInfo.SetXmlPropertyDouble("genxml/shippingcost", "0");
            cartInfo.SetXmlPropertyDouble("genxml/shippingcostTVA", "0");
            cartInfo.SetXmlPropertyDouble("genxml/shippingdealercost", "0");
            var modCtrl = new NBrightBuyController();
            var info    = modCtrl.GetByGuidKey(PortalSettings.Current.PortalId, -1, "SHIPPING", Shippingkey);

            if (info == null)
            {
                return(cartInfo);
            }


            double shippingcost = 0;

            if (cartInfo.GetXmlPropertyInt("genxml/OS_AllShippinglistidx") == 1)
            {
                shippingcost = 99.99;
            }

            if (Merchant.IsEnable && Merchant.Type == "B")
            {
                shippingcost = Merchant.HomeCost;

                if (cartInfo.GetXmlPropertyDouble("genxml/appliedsubtotal") >= Merchant.FreeCost)
                {
                    shippingcost = 0;
                }
            }


            var shippingdealercost = shippingcost;

            cartInfo.SetXmlPropertyDouble("genxml/shippingcostTVA", "0");
            cartInfo.SetXmlPropertyDouble("genxml/shippingcost", shippingcost);
            cartInfo.SetXmlPropertyDouble("genxml/shippingdealercost", shippingdealercost);

            return(cartInfo);
        }
Esempio n. 14
0
        private void PopulateData(String shippingkey)
        {
            var modCtrl = new NBrightBuyController();

            Info = modCtrl.GetByGuidKey(PortalSettings.Current.PortalId, -1, "SHIPPING", shippingkey);
            if (Info == null)
            {
                Info          = new NBrightInfo(true);
                Info.GUIDKey  = shippingkey;
                Info.TypeCode = "SHIPPING";
                Info.ModuleId = -1;
                Info.PortalId = PortalSettings.Current.PortalId;
            }
            _shippingList = GetRuleList();

            // build range Data
            _rangeData = new List <RangeItem>();
            foreach (var i in _shippingList)
            {
                var rangeList = i.GetXmlProperty("genxml/textbox/shiprange");
                var rl        = rangeList.Split(new string[] { "\n", "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
                foreach (var s in rl)
                {
                    var ri = s.Split('=');
                    if (ri.Count() == 2 && Utils.IsNumeric(ri[1]))
                    {
                        var riV = ri[0].Split('-');
                        if (riV.Count() == 2 && Utils.IsNumeric(riV[0]) && Utils.IsNumeric(riV[1]))
                        {
                            var rItem = new RangeItem();
                            rItem.RefCsv    = "," + i.GetXmlProperty("genxml/textbox/shipref") + ",";
                            rItem.RangeLow  = Convert.ToDouble(riV[0], CultureInfo.GetCultureInfo("en-US"));
                            rItem.Cost      = Convert.ToDouble(ri[1], CultureInfo.GetCultureInfo("en-US"));
                            rItem.RangeHigh = Convert.ToDouble(riV[1], CultureInfo.GetCultureInfo("en-US"));
                            _rangeData.Add(rItem);
                        }
                    }
                }
            }
        }
Esempio n. 15
0
 public string AddGroupFilter(HttpContext context, string editLangCurrent)
 {
     try
     {
         EditLangCurrent = editLangCurrent;
         var ajaxInfo = NBrightBuyUtils.GetAjaxInfo(context);
         var catid    = ajaxInfo.GetXmlPropertyInt("genxml/hidden/selectedcatid");
         var groupref = ajaxInfo.GetXmlProperty("genxml/hidden/selectedgroupref");
         if (catid > 0 && groupref != "")
         {
             var grp = _objCtrl.GetByGuidKey(PortalSettings.Current.PortalId, -1, "GROUP", groupref);
             if (grp != null)
             {
                 var catData = new CategoryData(catid, EditLangCurrent);
                 catData.AddFilterGroup(grp.ItemID);
             }
         }
     }
     catch (Exception e)
     {
         return(e.ToString());
     }
     return(CategoryGroupFilters(context, EditLangCurrent));
 }
        public static NBrightInfo GetProviderSettings(String ctrlkey)
        {
            var info = (NBrightInfo)Utils.GetCache("NBrightPxPayPaymentProvider" + PortalSettings.Current.PortalId.ToString(""));

            if (info == null)
            {
                var modCtrl = new NBrightBuyController();

                info = modCtrl.GetByGuidKey(PortalSettings.Current.PortalId, -1, "NBrightPxPayPAYMENT", ctrlkey);

                if (info == null)
                {
                    info          = new NBrightInfo(true);
                    info.GUIDKey  = ctrlkey;
                    info.TypeCode = "NBrightPxPayPAYMENT";
                    info.ModuleId = -1;
                    info.PortalId = PortalSettings.Current.PortalId;
                }

                Utils.SetCache("NBrightPxPayPaymentProvider" + PortalSettings.Current.PortalId.ToString(""), info);
            }

            return(info);
        }
Esempio n. 17
0
        private void DoImport(NBrightInfo nbi)
        {
            var fname = StoreSettings.Current.FolderTempMapPath + "\\" + nbi.GetXmlProperty("genxml/hidden/hiddatafile");

            if (System.IO.File.Exists(fname))
            {
                var xmlFile = new XmlDocument();
                try
                {
                    xmlFile.Load(fname);
                }
                catch (Exception e)
                {
                    Exceptions.LogException(e);
                    NBrightBuyUtils.SetNotfiyMessage(ModuleId, "xmlloadfail", NotifyCode.fail, ControlPath + "/App_LocalResources/Import.ascx.resx");
                    return;
                }

                // Ref old cat id , id new cat
                ////////////////////////////////////////////////////////////////////////////
                Dictionary <string, int> categoryListIDGiud   = new Dictionary <string, int>();
                Dictionary <int, int>    categoryListIDFather = new Dictionary <int, int>();
                ///////////////////////////////////////////////////////////////////////////

                var objCtrl = new NBrightBuyController();

                // get all valid languages
                var langList = DnnUtils.GetCultureCodeList(PortalId);
                foreach (var lang in langList)
                {
                    //Import Categories

                    #region "categories"

                    var nodList = xmlFile.SelectNodes("root/categories/" + lang + "/NB_Store_CategoriesInfo");
                    if (nodList != null)
                    {
                        var categoryid = -1;
                        foreach (XmlNode nod in nodList)
                        {
                            try
                            {
                                //if category Id exist replage guidKey
                                var guidKeyNod = nod.SelectSingleNode("CategoryID").InnerText;
                                if (guidKeyNod != null)
                                {
                                    var guidKey = guidKeyNod;
                                    categoryid = -1;
                                    // see if category already exists (update if so)
                                    var nbiImport = objCtrl.GetByGuidKey(PortalSettings.Current.PortalId, -1, "CATEGORY", guidKey);
                                    if (nbiImport != null)
                                    {
                                        categoryid = nbiImport.ItemID;
                                    }
                                    var CategoryData = new CategoryData(categoryid, lang);

                                    // clear down existing XML data
                                    var i = new NBrightInfo(true);
                                    i.PortalId = PortalSettings.Current.PortalId;
                                    CategoryData.DataRecord.XMLData     = i.XMLData;
                                    CategoryData.DataLangRecord.XMLData = i.XMLData;

                                    // assign guidkey to legacy productid (guidKey)
                                    CategoryData.DataRecord.GUIDKey = guidKey;
                                    CategoryData.DataRecord.SetXmlProperty("genxml/textbox/txtcategoryref", guidKey);

                                    // do mapping of XML data
                                    // DATA FIELDS
                                    var cD_CategoryID          = nod.SelectSingleNode("CategoryID").InnerText;
                                    var cD_PortalID            = nod.SelectSingleNode("PortalID").InnerText;
                                    var cD_Archived            = nod.SelectSingleNode("Archived").InnerText;
                                    var cD_Hide                = nod.SelectSingleNode("Hide").InnerText;
                                    var cD_CreatedByUser       = nod.SelectSingleNode("CreatedByUser").InnerText;
                                    var cD_CreatedDate         = nod.SelectSingleNode("CreatedDate").InnerText;
                                    var cD_ParentCategoryID    = nod.SelectSingleNode("ParentCategoryID").InnerText;
                                    var cD_ListOrder           = nod.SelectSingleNode("ListOrder").InnerText;
                                    var cD_Lang                = nod.SelectSingleNode("Lang").InnerText;
                                    var cD_ProductCount        = nod.SelectSingleNode("ProductCount").InnerText;
                                    var cD_ProductTemplate     = nod.SelectSingleNode("ProductTemplate").InnerText;
                                    var cD_ListItemTemplate    = nod.SelectSingleNode("ListItemTemplate").InnerText;
                                    var cD_ListAltItemTemplate = nod.SelectSingleNode("ListAltItemTemplate").InnerText;
                                    var cD_ImageURL            = nod.SelectSingleNode("ImageURL").InnerText;

                                    // DATA LANG FIELDS
                                    var cL_CategoryName    = nod.SelectSingleNode("CategoryName").InnerText;
                                    var cL_ParentName      = nod.SelectSingleNode("ParentName").InnerText;
                                    var cL_CategoryDesc    = nod.SelectSingleNode("CategoryDesc").InnerText;
                                    var cL_Message         = nod.SelectSingleNode("Message").InnerText;
                                    var cL_SEOPageTitle    = nod.SelectSingleNode("SEOPageTitle").InnerText;
                                    var cL_SEOName         = nod.SelectSingleNode("SEOName").InnerText;
                                    var cL_MetaDescription = nod.SelectSingleNode("MetaDescription").InnerText;
                                    var cL_MetaKeywords    = nod.SelectSingleNode("MetaKeywords").InnerText;

                                    // Populate DATA CATEGORY
                                    CategoryData.DataRecord.SetXmlProperty("genxml/hidden/recordsortorder", cD_ListOrder);
                                    CategoryData.DataRecord.SetXmlProperty("genxml/checkbox/chkishidden", cD_Hide);
                                    CategoryData.DataRecord.SetXmlProperty("genxml/checkbox/chkdisable", "False");
                                    CategoryData.DataRecord.SetXmlProperty("genxml/dropdownlist/ddlgrouptype", "cat");

                                    if (cD_ParentCategoryID != null && cD_ParentCategoryID != "0")
                                    {
                                        CategoryData.DataRecord.SetXmlProperty("genxml/dropdownlist/ddlparentcatid", cD_ParentCategoryID);
                                    }

                                    // Populate DATA CATEGORY LANG


                                    if (cL_CategoryName != null && cL_CategoryName != "")
                                    {
                                        CategoryData.DataLangRecord.SetXmlProperty("genxml/textbox/txtcategoryname", cL_CategoryName);
                                    }
                                    if (cL_CategoryDesc != null && cL_CategoryDesc != "")
                                    {
                                        CategoryData.DataLangRecord.SetXmlProperty("genxml/textbox/txtcategorydesc", cL_CategoryDesc);
                                    }
                                    if (cL_MetaDescription != null && cL_MetaDescription != "")
                                    {
                                        CategoryData.DataLangRecord.SetXmlProperty("genxml/textbox/txtmetadescription", cL_MetaDescription);
                                    }
                                    if (cL_MetaKeywords != null && cL_MetaKeywords != "")
                                    {
                                        CategoryData.DataLangRecord.SetXmlProperty("genxml/textbox/txtmetakeywords", cL_MetaKeywords);
                                    }
                                    if (cL_SEOPageTitle != null && cL_SEOPageTitle != "")
                                    {
                                        CategoryData.DataLangRecord.SetXmlProperty("genxml/textbox/txtseopagetitle", cL_SEOPageTitle);
                                    }
                                    if (cL_SEOName != null && cL_SEOName != "")
                                    {
                                        CategoryData.DataLangRecord.SetXmlProperty("genxml/textbox/txtseoname", cL_SEOName);
                                    }
                                    if (cL_Message != null && cL_Message != "")
                                    {
                                        CategoryData.DataLangRecord.SetXmlProperty("genxml/edt/message", cL_Message);
                                    }

                                    categoryListIDGiud.Add(CategoryData.CategoryRef, CategoryData.CategoryId);
                                    if (cD_ParentCategoryID != null && cD_ParentCategoryID != "" && cD_ParentCategoryID != "0")
                                    {
                                        categoryListIDFather.Add(CategoryData.CategoryId, Convert.ToInt32(cD_ParentCategoryID));
                                    }


                                    CategoryData.Save();
                                }
                            }
                            catch (Exception e)
                            {
                                var logMessage = "CATEGORY: CategoryId: " + categoryid.ToString() + " : " + e.ToString();
                                LogOutput.LogWrite(logMessage);
                            }
                        }

                        //loop on The dictionary
                        foreach (var catl in categoryListIDFather)
                        {
                            //Key
                            var tempNewID = catl.Key;
                            //Value
                            var tempOldFather = catl.Value;

                            var tempNewFather = categoryListIDGiud[tempOldFather.ToString()];

                            var CategoryData = new CategoryData(tempNewID, lang);
                            CategoryData.ParentItemId = tempNewFather;
                            CategoryData.DataRecord.SetXmlProperty("genxml/dropdownlist/ddlparentcatid", tempNewFather.ToString());
                            CategoryData.Save();
                        }
                    }

                    #endregion

                    // Import Products

                    #region "data"

                    nodList = xmlFile.SelectNodes("root/products/" + lang + "/P");
                    if (nodList != null)
                    {
                        var productid = -1;
                        var prodname  = "";
                        foreach (XmlNode nod in nodList)
                        {
                            try
                            {
                                var guidKeyNod = nod.SelectSingleNode("NB_Store_ProductsInfo/ProductID");
                                if (guidKeyNod != null)
                                {
                                    var guidKey = guidKeyNod.InnerText;
                                    productid = -1;
                                    // See if e already have a product imported, if so we want to update (maybe multiple languages, or a 2nd migrate)
                                    var nbiImport = objCtrl.GetByGuidKey(PortalSettings.Current.PortalId, -1, "PRD", guidKey);
                                    if (nbiImport != null)
                                    {
                                        productid = nbiImport.ItemID;
                                    }
                                    var productData = new ProductData(productid, lang);

                                    productid = productData.Info.ItemID; // set productid, so we have the id if it goes wrong.
                                    prodname  = productData.ProductName;

                                    // clear down existing XML data
                                    var i = new NBrightInfo(true);
                                    productData.DataRecord.XMLData     = i.XMLData;
                                    productData.DataLangRecord.XMLData = i.XMLData;

                                    // assign guidkey to legacy productid (guidKey)
                                    productData.DataRecord.GUIDKey = guidKey;
                                    productData.DataRecord.SetXmlProperty("genxml/importref", guidKey);

                                    // do mapping of XML data
                                    // DATA FIELDS
                                    var pD_ProductID     = nod.SelectSingleNode("NB_Store_ProductsInfo/ProductID").InnerText;
                                    var pD_PortalID      = nod.SelectSingleNode("NB_Store_ProductsInfo/PortalID").InnerText;
                                    var pD_TaxCategoryID = nod.SelectSingleNode("NB_Store_ProductsInfo/TaxCategoryID").InnerText;
                                    var pD_Featured      = nod.SelectSingleNode("NB_Store_ProductsInfo/Featured").InnerText;
                                    var pD_Archived      = nod.SelectSingleNode("NB_Store_ProductsInfo/Archived").InnerText;
                                    var pD_CreatedByUser = nod.SelectSingleNode("NB_Store_ProductsInfo/CreatedByUser").InnerText;
                                    var pD_CreatedDate   = nod.SelectSingleNode("NB_Store_ProductsInfo/CreatedDate").InnerText;
                                    var pD_IsDeleted     = nod.SelectSingleNode("NB_Store_ProductsInfo/IsDeleted").InnerText;
                                    var pD_ProductRef    = nod.SelectSingleNode("NB_Store_ProductsInfo/ProductRef").InnerText;
                                    var pD_Lang          = nod.SelectSingleNode("NB_Store_ProductsInfo/Lang").InnerText;
                                    var pD_Manufacturer  = nod.SelectSingleNode("NB_Store_ProductsInfo/Manufacturer").InnerText;
                                    var pD_ModifiedDate  = nod.SelectSingleNode("NB_Store_ProductsInfo/ModifiedDate").InnerText;
                                    var pD_IsHidden      = nod.SelectSingleNode("NB_Store_ProductsInfo/IsHidden").InnerText;
                                    // DATA LANG FIELDS
                                    var pL_ProductName = nod.SelectSingleNode("NB_Store_ProductsInfo/ProductName").InnerText;
                                    var pL_Summary     = nod.SelectSingleNode("NB_Store_ProductsInfo/Summary").InnerText;
                                    var pL_Description = nod.SelectSingleNode("NB_Store_ProductsInfo/Description").InnerText;
                                    var pL_SEOName     = nod.SelectSingleNode("NB_Store_ProductsInfo/SEOName").InnerText;
                                    var pL_TagWords    = nod.SelectSingleNode("NB_Store_ProductsInfo/TagWords").InnerText;
                                    var pL_Desc        = nod.SelectSingleNode("NB_Store_ProductsInfo/Description").InnerText;

                                    if (pD_ProductRef != null)
                                    {
                                        productData.DataRecord.SetXmlProperty("genxml/textbox/txtproductref", pD_ProductRef);
                                    }
                                    if (pD_Manufacturer != null)
                                    {
                                        productData.DataRecord.SetXmlProperty("genxml/textbox/customorder", pD_Manufacturer);
                                    }

                                    // langauge main fields
                                    if (pL_ProductName != null)
                                    {
                                        productData.DataLangRecord.SetXmlProperty("genxml/textbox/txtproductname", pL_ProductName);
                                    }
                                    if (pL_Summary != null)
                                    {
                                        productData.DataLangRecord.SetXmlProperty("genxml/textbox/txtsummary", pL_Summary);
                                    }
                                    if (pL_SEOName != null)
                                    {
                                        productData.DataLangRecord.SetXmlProperty("genxml/textbox/txtseoname", pL_SEOName);
                                    }
                                    if (pL_SEOName != null)
                                    {
                                        productData.DataLangRecord.SetXmlProperty("genxml/textbox/txtseopagetitle", pL_SEOName);
                                    }
                                    if (pL_TagWords != null)
                                    {
                                        productData.DataLangRecord.SetXmlProperty("genxml/textbox/txttagwords", pL_TagWords);
                                    }

                                    //edt

                                    if (pL_Desc != null)
                                    {
                                        productData.DataLangRecord.SetXmlProperty("genxml/edt", "");
                                        productData.DataLangRecord.SetXmlProperty("genxml/edt/description", pL_Desc);
                                    }


                                    ////////////////////////////// CUSTOM FIELDS /////////////////////////////////////
                                    ////////////////////////////// CUSTOM FIELDS /////////////////////////////////////
                                    ////////////////////////////// CUSTOM FIELDS /////////////////////////////////////
                                    #region "Custom Fields"

                                    // Custom Fields the Custom fields in Nbstore are stored in XmlData xml file area.

                                    if (nod.SelectSingleNode("NB_Store_ProductsInfo/XMLData").FirstChild != null) // verify if there are custom fileds
                                    {
                                        var InputCustomFieldsXml = new XmlDocument();
                                        InputCustomFieldsXml.Load(new StringReader(nod.SelectSingleNode("NB_Store_ProductsInfo/XMLData").InnerText));
                                        var nodListCustom = InputCustomFieldsXml.SelectSingleNode("genxml");
                                        var custominfo    = new NBrightInfo();
                                        custominfo.XMLData = nodListCustom.OuterXml;

                                        // ***************************
                                        // process custom fields here.
                                        // ***************************
                                    }

                                    #endregion
                                    ////////////////////////////// END CUSTOM FIELDS /////////////////////////////////////
                                    ////////////////////////////// END CUSTOM FIELDS /////////////////////////////////////
                                    ////////////////////////////// END CUSTOM FIELDS /////////////////////////////////////


                                    // Models
                                    var nodListModels = nod.SelectNodes("M/NB_Store_ModelInfo");
                                    foreach (XmlNode nodMod in nodListModels)
                                    {
                                        //load single node module strucuture
                                        var ModelID = nodMod.SelectSingleNode("ModelID").InnerText;

                                        var ProductID    = nodMod.SelectSingleNode("ProductID").InnerText;
                                        var ListOrder    = nodMod.SelectSingleNode("ListOrder").InnerText;
                                        var UnitCost     = nodMod.SelectSingleNode("UnitCost").InnerText;
                                        var Barcode      = nodMod.SelectSingleNode("Barcode").InnerText;
                                        var ModelRef     = nodMod.SelectSingleNode("ModelRef").InnerText;
                                        var Lang         = nodMod.SelectSingleNode("Lang").InnerText;
                                        var ModelName    = nodMod.SelectSingleNode("ModelName").InnerText;
                                        var QtyRemaining = nodMod.SelectSingleNode("QtyRemaining").InnerText;
                                        var QtyTrans     = nodMod.SelectSingleNode("QtyTrans").InnerText;
                                        var QtyTransDate = nodMod.SelectSingleNode("QtyTransDate").InnerText;
                                        var ProductName  = nodMod.SelectSingleNode("ProductName").InnerText;
                                        var PortalID     = nodMod.SelectSingleNode("PortalID").InnerText;
                                        var Weight       = nodMod.SelectSingleNode("Weight").InnerText;
                                        var Height       = nodMod.SelectSingleNode("Height").InnerText;
                                        var Length       = nodMod.SelectSingleNode("Length").InnerText;
                                        var Width        = nodMod.SelectSingleNode("Width").InnerText;
                                        var Deleted      = nodMod.SelectSingleNode("Deleted").InnerText;
                                        var QtyStockSet  = nodMod.SelectSingleNode("QtyStockSet").InnerText;
                                        var DealerCost   = nodMod.SelectSingleNode("DealerCost").InnerText;
                                        var PurchaseCost = nodMod.SelectSingleNode("PurchaseCost").InnerText;
                                        var XMLData      = nodMod.SelectSingleNode("XMLData").InnerText;
                                        var Extra        = nodMod.SelectSingleNode("Extra").InnerText;
                                        var DealerOnly   = nodMod.SelectSingleNode("DealerOnly").InnerText;
                                        var Allow        = nodMod.SelectSingleNode("Allow").InnerText;


                                        ////////////////////////////// FINE CUSTOM FIELDS /////////////////////////////////////
                                        ////////////////////////////// FINE CUSTOM FIELDS /////////////////////////////////////
                                        ////////////////////////////// FINE CUSTOM FIELDS /////////////////////////////////////



                                        //il dentro al tag model cè un genxml che identifica il modello
                                        // MODELLI CAMPI DATA
                                        ////////////////////////////// MODELS /////////////////////////////////////
                                        ////////////////////////////// MODELS /////////////////////////////////////
                                        ////////////////////////////// MODELS /////////////////////////////////////
                                        var newkey = Utils.GetUniqueKey();

                                        var strXmlModel = @"<genxml><models><genxml>
                                      <files />
                                      <hidden><modelid>" + newkey + "</modelid>" +
                                                          @"</hidden>
                                      <textbox>
                                        <availabledate datatype=""date"" />
                                        <txtqtyminstock>0</txtqtyminstock>
                                        <txtmodelref>" + ModelRef + @"</txtmodelref>
                                        <txtunitcost>" + UnitCost + @"</txtunitcost>
                                        <txtsaleprice>0.00</txtsaleprice>
                                        <txtbarcode>" + Barcode + @"</txtbarcode>
                                        <txtqtyremaining>" + QtyRemaining + @"</txtqtyremaining>
                                        <txtqtystockset>" + QtyStockSet + @"</txtqtystockset>
                                        <txtdealercost>" + DealerCost + @"</txtdealercost>
                                        <txtpurchasecost>" + PurchaseCost + @"</txtpurchasecost>
                                        <weight>" + Weight + @"</weight>
                                        <depth>" + Length + @"</depth>
                                        <width>" + Width + @"</width>
                                        <height>" + Height + @"</height>
                                        <unit />
                                        <delay />
                                      </textbox>
                                      <checkbox>
                                        <chkstockon>False</chkstockon>
                                        <chkishidden>False</chkishidden>
                                        <chkdeleted>False</chkdeleted>
                                        <chkdealeronly>False</chkdealeronly>
                                      </checkbox>
                                      <dropdownlist>
                                        <modelstatus>010</modelstatus>
                                      </dropdownlist>
                                      <checkboxlist />
                                      <radiobuttonlist />
                                    </genxml></models></genxml>";

                                        var strXmlModelLang = @"<genxml><models><genxml>
                                        <files />
                                        <hidden />
                                        <textbox>
                                            <txtmodelname>" + ModelName + "</txtmodelname>" +
                                                              "<txtextra>" + Extra + @"</txtextra>
                                        </textbox>
                                        <checkbox /><dropdownlist /><checkboxlist /><radiobuttonlist />
                                        </genxml></models></genxml>";

                                        if (productData.DataRecord.XMLDoc.SelectSingleNode("genxml/models") == null)
                                        {
                                            productData.DataRecord.AddXmlNode(strXmlModel, "genxml/models", "genxml");
                                            productData.DataLangRecord.AddXmlNode(strXmlModelLang, "genxml/models", "genxml");
                                        }
                                        else
                                        {
                                            productData.DataRecord.AddXmlNode(strXmlModel, "genxml/models/genxml", "genxml/models");
                                            productData.DataLangRecord.AddXmlNode(strXmlModelLang, "genxml/models/genxml", "genxml/models");
                                        }
                                    }

                                    ////////////////////////////// IMAGES /////////////////////////////////////
                                    ////////////////////////////// IMAGES /////////////////////////////////////
                                    ////////////////////////////// IMAGES /////////////////////////////////////
                                    ////////////////////////////// IMAGES /////////////////////////////////////
                                    // copy all the images from Portals\0\productimages to Portals\0\NBStore\images

                                    var nodListImages = nod.SelectNodes("I/NB_Store_ProductImageInfo");
                                    foreach (XmlNode nodImg in nodListImages)
                                    {
                                        var ImageID   = nodImg.SelectSingleNode("ImageID").InnerText;
                                        var Hidden    = nodImg.SelectSingleNode("Hidden").InnerText;
                                        var ImageUrl  = nodImg.SelectSingleNode("ImageURL").InnerText;
                                        var ImagePath = nodImg.SelectSingleNode("ImagePath").InnerText;

                                        productData.AddNewImage(ImageUrl, ImagePath);
                                    }
                                    ////////////////////////////// DOCS /////////////////////////////////////
                                    ////////////////////////////// DOCS /////////////////////////////////////
                                    ////////////////////////////// DOCS /////////////////////////////////////
                                    ////////////////////////////// DOCS /////////////////////////////////////
                                    // copy all the DOCS from Portals\0\productdocs to Portals\0\NBStore\docs

                                    var nodListDocs = nod.SelectNodes("D/NB_Store_ProductDocInfo");
                                    var lp          = 1;
                                    var objCtrlDoc  = new NBrightBuyController();

                                    foreach (XmlNode nodDoc in nodListDocs)
                                    {
                                        var DocID     = nodDoc.SelectSingleNode("DocID").InnerText;
                                        var ProductID = nodDoc.SelectSingleNode("ProductID").InnerText;
                                        var DocPath   = nodDoc.SelectSingleNode("DocPath").InnerText;
                                        var ListOrder = nodDoc.SelectSingleNode("ListOrder").InnerText;
                                        var Hidden    = nodDoc.SelectSingleNode("Hidden").InnerText;
                                        var FileName  = nodDoc.SelectSingleNode("FileName").InnerText;
                                        var FileExt   = nodDoc.SelectSingleNode("FileExt").InnerText;
                                        var Lang      = nodDoc.SelectSingleNode("Lang").InnerText;
                                        var DocDesc   = nodDoc.SelectSingleNode("DocDesc").InnerText;

                                        productData.AddNewDoc(DocPath, FileName);

                                        productData.DataRecord.SetXmlProperty("genxml/docs/genxml[" + lp.ToString() + "]/hidden/fileext", FileExt);
                                        DocPath = DocPath.Replace("productdocs", @"NBStore\docs");
                                        productData.DataRecord.SetXmlProperty("genxml/docs/genxml[" + lp.ToString() + "]/hidden/filepath", DocPath);

                                        objCtrlDoc.Update(productData.DataRecord);

                                        // if doesen't exisit the xml genxml strucuture inside the DataLangRecor I create it
                                        var strXml = "<genxml><docs><genxml><textbox/></genxml></docs></genxml>";
                                        if (productData.DataLangRecord.XMLDoc.SelectSingleNode("genxml/docs") == null)
                                        {
                                            productData.DataLangRecord.AddXmlNode(strXml, "genxml/docs", "genxml");
                                        }
                                        else
                                        {
                                            productData.DataLangRecord.AddXmlNode(strXml, "genxml/docs/genxml", "genxml/docs");
                                        }
                                        /////////////////////////////////////////////////
                                        productData.DataLangRecord.SetXmlProperty("genxml/docs/genxml[" + lp.ToString() + "]/textbox/txtdocdesc", DocDesc);
                                        productData.DataLangRecord.SetXmlProperty("genxml/docs/genxml[" + lp.ToString() + "]/textbox/txttitle", FileName);

                                        objCtrlDoc.Update(productData.DataLangRecord);


                                        lp += 1;
                                    }



                                    ////////////////////////////// CATEGORIES /////////////////////////////////////
                                    ////////////////////////////// CATEGORIES /////////////////////////////////////
                                    ////////////////////////////// CATEGORIES /////////////////////////////////////
                                    ////////////////////////////// CATEGORIES /////////////////////////////////////

                                    var nodListCat = nod.SelectNodes("C/NB_Store_ProductCategoryInfo");
                                    foreach (XmlNode nodCat in nodListCat)
                                    {
                                        var ProductID  = nodCat.SelectSingleNode("ProductID").InnerText;
                                        var CategoryID = nodCat.SelectSingleNode("CategoryID").InnerText;

                                        if (ProductID == guidKey)
                                        {
                                            if (categoryListIDGiud.ContainsKey(CategoryID))
                                            {
                                                var newCategoryId = categoryListIDGiud[CategoryID];
                                                productData.AddCategory(newCategoryId);
                                            }
                                        }
                                    }



                                    ////////////////////////////// SAVE PRODUCT /////////////////////////////////////
                                    productData.Save();
                                }
                            }
                            catch (Exception e)
                            {
                                var logMessage = "PRODUCTS: " + prodname + " ProductId: " + productid.ToString() + " : " + e.ToString();
                                LogOutput.LogWrite(logMessage);
                            }
                        }
                    }

                    ////////////////////////////// RELATED PRODUCTS /////////////////////////////////////
                    //recicle on all the xml import Product and reconnect the related product
                    foreach (var lang2 in langList)
                    {
                        if (nodList != null)
                        {
                            foreach (XmlNode nod in nodList)
                            {
                                var guidKeyNod = nod.SelectSingleNode("NB_Store_ProductsInfo/ProductID");
                                if (guidKeyNod != null)
                                {
                                    var guidKey   = guidKeyNod.InnerText;
                                    var productid = -1;
                                    try
                                    {
                                        // See if e already have a product imported, if so we want to update (maybe multiple languages, or a 2nd migrate)
                                        var nbiImport = objCtrl.GetByGuidKey(PortalSettings.Current.PortalId, -1, "PRD", guidKey);
                                        if (nbiImport != null)
                                        {
                                            productid = nbiImport.ItemID;
                                        }
                                        var productData = new ProductData(productid, lang2);

                                        ////////////////////////////// RELATED PRODUCTS /////////////////////////////////////
                                        ////////////////////////////// RELATED PRODUCTS /////////////////////////////////////
                                        var nodListRelated = nod.SelectNodes("R/NB_Store_ProductRelatedInfo");
                                        if (nodListRelated != null) //if there are related
                                        {
                                            foreach (XmlNode nodRel in nodListRelated)
                                            {
                                                // id in the related product import file
                                                var ImportRelatedProductID = nodRel.SelectSingleNode("RelatedProductID").InnerText;
                                                // extract Id of the new created product thet have the old id in the guidKey
                                                var tempID = objCtrl.GetByGuidKey(PortalSettings.Current.PortalId, -1, "PRD", ImportRelatedProductID);

                                                if (tempID != null)
                                                {
                                                    int IDRelatedprod = tempID.ItemID;
                                                    productData.AddRelatedProduct(IDRelatedprod);
                                                    productData.Save();
                                                }
                                            }
                                        }
                                    }
                                    catch (Exception e)
                                    {
                                        var logMessage = "RELATED PRODUCTS: ProductId: " + productid.ToString() + " : " + e.ToString();
                                        LogOutput.LogWrite(logMessage);
                                    }
                                }
                            }
                        }
                    }

                    LogOutput.LogWrite("END: " + DateTime.Now);

                    #endregion
                }

                NBrightBuyUtils.SetNotfiyMessage(ModuleId, "Import", NotifyCode.ok, ControlPath + "/App_LocalResources/Import.ascx.resx");
            }
        }
Esempio n. 18
0
        private static NBrightInfo _nbrightInfo()
        {
            NBrightBuyController _nBright = new NBrightBuyController();

            return(_nBright.GetByGuidKey(PortalSettings.Current.PortalId, -1, "SHIPPING", "OS_AllShipping"));
        }
Esempio n. 19
0
        public override NBrightInfo CalculateVoucherAmount(int portalId, int userId, NBrightInfo cartInfo, string discountcode)
        {
            cartInfo.SetXmlPropertyDouble("genxml/discountstatus", "");
            cartInfo.SetXmlPropertyDouble("genxml/voucherdiscount", "0"); // reset discount amount
            Double discountcodeamt = 0;

            if (userId > 0)
            {
                var clientData = new ClientData(portalId, userId);
                if (clientData.DiscountCodes.Count > 0)
                {
                    var subtotal = cartInfo.GetXmlPropertyDouble("genxml/subtotal");
                    // do client voucher discount on total cart
                    foreach (var d in clientData.VoucherCodes)
                    {
                        var validutil     = d.GetXmlProperty("genxml/textbox/validuntil");
                        var validutildate = DateTime.Today;
                        if (Utils.IsDate(validutil))
                        {
                            validutildate = Convert.ToDateTime(validutil);
                        }
                        if (d.GetXmlProperty("genxml/textbox/coderef").ToLower() == discountcode.ToLower() && validutildate >= DateTime.Today)
                        {
                            var amount = d.GetXmlPropertyDouble("genxml/textbox/amount");
                            if (amount > 0)
                            {
                                if (subtotal >= amount)
                                {
                                    discountcodeamt = amount;
                                }
                                else
                                {
                                    discountcodeamt = subtotal;
                                }
                                cartInfo.SetXmlPropertyDouble("genxml/discountstatus", "valid");
                            }
                            else
                            {
                                cartInfo.SetXmlPropertyDouble("genxml/discountstatus", "invalid");
                            }
                        }
                        if (discountcodeamt > 0)
                        {
                            break;
                        }
                    }
                }
            }

            if (discountcodeamt == 0) // if no client level, calc any portal level percentage discount
            {
                var objCtrl = new NBrightBuyController();
                var d       = objCtrl.GetByGuidKey(portalId, -1, "DISCOUNTCODE", discountcode);
                if (d != null)
                {
                    var validutil     = d.GetXmlProperty("genxml/textbox/validuntil");
                    var validutildate = DateTime.Today;
                    if (Utils.IsDate(validutil))
                    {
                        validutildate = Convert.ToDateTime(validutil);
                    }
                    if (validutildate >= DateTime.Today && d.GetXmlProperty("genxml/radiobuttonlist/amounttype") == "1")
                    {
                        var minamountlimit  = d.GetXmlPropertyDouble("genxml/textbox/minamountlimit");
                        var amount          = d.GetXmlPropertyDouble("genxml/textbox/amount");
                        var usage           = d.GetXmlPropertyDouble("genxml/textbox/usage");
                        var usagelimit      = d.GetXmlPropertyDouble("genxml/textbox/usagelimit");
                        var appliedsubtotal = cartInfo.GetXmlPropertyDouble("genxml/appliedsubtotal");
                        if (amount > 0 && (usagelimit == 0 || usagelimit > usage) && (appliedsubtotal >= minamountlimit))
                        {
                            discountcodeamt = amount;
                            cartInfo.SetXmlPropertyDouble("genxml/discountstatus", "valid");
                        }
                        else
                        {
                            cartInfo.SetXmlPropertyDouble("genxml/discountstatus", "invalid");
                        }
                    }
                }
            }

            cartInfo.SetXmlPropertyDouble("genxml/voucherdiscount", discountcodeamt); // reset discount amount

            return(cartInfo);
        }
        public override string DoWork(int portalId)
        {
            try
            {
                var objCtrl = new NBrightBuyController();
                var rtnmsg  = "";
                // check if we have NBS in this portal by looking for default settings.
                var nbssetting = objCtrl.GetByGuidKey(portalId, -1, "SETTINGS", "NBrightBuySettings");
                if (nbssetting != null)
                {
                    var pluginData = new PluginData(portalId);     // get plugin data to see if this scheduler is active on this portal
                    var plugin     = pluginData.GetPluginByCtrl("cartreview");
                    if (plugin != null && plugin.GetXmlPropertyBool("genxml/checkbox/active"))
                    {
                        var doscheduler = false;
                        // The NBS scheduler is normally set to run hourly, therefore if we only want a process to run daily we need the logic in this function.
                        // To do this we keep a last run flag on the sceduler settings
                        var setting = objCtrl.GetByGuidKey(portalId, -1, "NBrightCartReview", "NBrightCartReviewScheduler");
                        if (setting == null)
                        {
                            setting          = new NBrightInfo(true);
                            setting.ItemID   = -1;
                            setting.PortalId = portalId;
                            setting.TypeCode = "NBrightCartReview";
                            setting.GUIDKey  = "NBrightCartReviewScheduler";
                            setting.ModuleId = -1;
                            setting.XMLData  = "<genxml></genxml>";
                            doscheduler      = true;
                        }

                        if (plugin.GetXmlPropertyBool("genxml/checkbox/testmode") == true)
                        {
                            doscheduler = true;
                        }
                        else
                        {
                            // check last run date (Only running once a day in this case)
                            var lastrun = setting.GetXmlProperty("genxml/lastrun");
                            if (Utils.IsDate(lastrun) && (Convert.ToDateTime(lastrun).AddDays(1) < DateTime.Now))
                            {
                                doscheduler = true;
                            }
                        }


                        if (doscheduler)
                        {
                            var daysforzero   = plugin.GetXmlPropertyInt("genxml/textbox/daysforzero");
                            var daysfornormal = plugin.GetXmlPropertyInt("genxml/textbox/daysfornormal");

                            PurgeZeroCarts(portalId, daysforzero);
                            PurgeCarts(portalId, daysfornormal);

                            setting.SetXmlProperty("genxml/lastrun", DateTime.Now.ToString("s"), TypeCode.DateTime);
                            objCtrl.Update(setting);
                            rtnmsg = " - NBrightCartReview  " + portalId + " OK ";
                        }
                    }
                }

                return(rtnmsg);
            }
            catch (Exception ex)
            {
                return(" - NBrightCartReview FAIL: " + ex.ToString() + " : ");
            }
        }