public override NBrightInfo UpdatePercentUsage(int portalId, int userId, NBrightInfo purchaseInfo) { if (userId <= 0) return purchaseInfo; var discountcode = purchaseInfo.GetXmlProperty("genxml/extrainfo/genxml/textbox/promocode"); if (!purchaseInfo.GetXmlPropertyBool("genxml/discountprocessed")) { if (discountcode == "") return purchaseInfo; var clientData = new ClientData(portalId, userId); if (clientData.DiscountCodes.Count == 0) return purchaseInfo; 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"); } return purchaseInfo; }
public void UpdateRule(Repeater rpData) { foreach (RepeaterItem i in rpData.Items) { var strXml = GenXmlFunctions.GetGenXml(i); var nbi = new NBrightInfo(true); nbi.XMLData = strXml; if (nbi.GetXmlPropertyBool("genxml/hidden/isdirty")) { UpdateRule(i); } } }
private Boolean IsModelInStock(NBrightInfo dataItem) { var stockOn = dataItem.GetXmlPropertyBool("genxml/checkbox/chkstockon"); if (stockOn) { var modelstatus = dataItem.GetXmlProperty("genxml/dropdownlist/modelstatus"); if (modelstatus == "010") return true; } else { return true; } return false; }
private String GetItemDisplay(NBrightInfo obj, String templ, Boolean displayPrices) { var isDealer = CmsProviderManager.Default.IsInRole(StoreSettings.DealerRole); var outText = templ; var stockOn = obj.GetXmlPropertyBool("genxml/checkbox/chkstockon"); var stock = obj.GetXmlPropertyDouble("genxml/textbox/txtqtyremaining"); if (stock > 0 || !stockOn) { outText = outText.Replace("{ref}", obj.GetXmlProperty("genxml/textbox/txtmodelref")); outText = outText.Replace("{name}", obj.GetXmlProperty("genxml/lang/genxml/textbox/txtmodelname")); outText = outText.Replace("{stock}", stock.ToString("")); if (displayPrices) { //[TODO: add promotional calc] var saleprice = obj.GetXmlPropertyDouble("genxml/textbox/txtsaleprice"); var price = obj.GetXmlPropertyDouble("genxml/textbox/txtunitcost"); var bestprice = price; if (saleprice > 0 && saleprice < price) bestprice = saleprice; var strprice = NBrightBuyUtils.FormatToStoreCurrency(price); var strbestprice = NBrightBuyUtils.FormatToStoreCurrency(bestprice); var strsaleprice = NBrightBuyUtils.FormatToStoreCurrency(saleprice); var strdealerprice = ""; var dealerprice = obj.GetXmlPropertyDouble("genxml/textbox/txtdealercost"); if (isDealer) { strdealerprice = NBrightBuyUtils.FormatToStoreCurrency(dealerprice); if (!outText.Contains("{dealerprice}") && (price > dealerprice)) strprice = strdealerprice; if (dealerprice < bestprice) bestprice = dealerprice; } outText = outText.Replace("{price}", "(" + strprice + ")"); outText = outText.Replace("{dealerprice}", strdealerprice); outText = outText.Replace("{bestprice}", strbestprice); outText = outText.Replace("{saleprice}", strsaleprice); } else { outText = outText.Replace("{price}", ""); outText = outText.Replace("{dealerprice}", ""); outText = outText.Replace("{bestprice}", ""); outText = outText.Replace("{saleprice}", ""); } return outText; } return ""; // no stock so return empty string. }
public static void SendEmail(String toEmail, String templateName, NBrightInfo dataObj, String emailsubjectresxkey, String fromEmail,String lang) { dataObj = ProcessEventProvider(EventActions.BeforeSendEmail, dataObj, templateName); if (!dataObj.GetXmlPropertyBool("genxml/stopprocess")) { if (lang == "") lang = Utils.GetCurrentCulture(); var emaillist = toEmail; if (emaillist != "") { var emailsubject = ""; if (emailsubjectresxkey != "") { var resxpath = StoreSettings.NBrightBuyPath() + "/App_LocalResources/Notification.ascx.resx"; emailsubject = DnnUtils.GetLocalizedString(emailsubjectresxkey, resxpath, lang); if (emailsubject == null) emailsubject = emailsubjectresxkey; } // we can't use StoreSettings.Current.Settings(), becuase of external calls from providers to this function, so load in the settings directly var modCtrl = new NBrightBuyController(); var storeSettings = modCtrl.GetStoreSettings(dataObj.PortalId); var strTempl = modCtrl.GetTemplateData(-1, templateName, lang, storeSettings.Settings(), storeSettings.DebugMode); var emailbody = GenXmlFunctions.RenderRepeater(dataObj, strTempl, "", "XMLData", lang, storeSettings.Settings()); if (templateName.EndsWith(".xsl")) emailbody = XslUtils.XslTransInMemory(dataObj.XMLData, emailbody); if (fromEmail == "") fromEmail = storeSettings.AdminEmail; var emailarray = emaillist.Split(','); emailsubject = storeSettings.Get("storename") + " : " + emailsubject; foreach (var email in emailarray) { if (!string.IsNullOrEmpty(email.Trim()) && Utils.IsEmail(fromEmail.Trim()) && Utils.IsEmail(email.Trim())) { // multiple attachments as csv with "|" seperator DotNetNuke.Services.Mail.Mail.SendMail(fromEmail.Trim(), email.Trim(), "", emailsubject, emailbody, dataObj.GetXmlProperty("genxml/emailattachment"), "HTML", "", "", "", ""); } } } } ProcessEventProvider(EventActions.AfterSendEmail, dataObj, templateName); }
/// <summary> /// Search filesystem for any new plugins that have been added. Removed any deleted ones. /// </summary> public static void UpdateSystemPlugins() { // Add new plugins var updated = false; var pluginfoldermappath = System.Web.Hosting.HostingEnvironment.MapPath(StoreSettings.NBrightBuyPath() + "/Plugins"); if (pluginfoldermappath != null && Directory.Exists(pluginfoldermappath)) { var objCtrl = new NBrightBuyController(); var flist = Directory.GetFiles(pluginfoldermappath, "*.xml"); foreach (var f in flist) { if (f.EndsWith(".xml")) { var datain = File.ReadAllText(f); try { var nbi = new NBrightInfo(); nbi.XMLData = datain; // check if we are injecting multiple var nodlist = nbi.XMLDoc.SelectNodes("genxml"); if (nodlist != null && nodlist.Count > 0) { foreach (XmlNode nod in nodlist) { var nbi2 = new NBrightInfo(); nbi2.XMLData = nod.OuterXml; nbi2.ItemID = -1; nbi2.GUIDKey = nbi.GetXmlProperty("genxml/textbox/ctrl"); nbi2.PortalId = 99999; nbi2.Lang = ""; nbi2.ParentItemId = 0; nbi2.ModuleId = -1; nbi2.XrefItemId = 0; nbi2.UserId = 0; nbi2.TypeCode = "PLUGIN"; // check if record exists (should NOT) but lets replace if it does. var existingrecord = objCtrl.GetByGuidKey(-1, -1, "PLUGIN", nbi2.GUIDKey); if (existingrecord != null) { nbi2.ItemID = existingrecord.ItemID; if (nbi2.GetXmlPropertyBool("genxml/delete")) { objCtrl.Delete(existingrecord.ItemID); } else { objCtrl.Update(nbi2); updated = true; } } else { objCtrl.Update(nbi2); updated = true; } } } if (updated) { File.Delete(f); //load entity typecode to DB idx settings. NBrightBuyUtils.RegisterEnityTypeToDataBase(); } } catch (Exception) { // data might not be XML complient (ignore) } } } } if (updated) { CopySystemPluginsToPortal(); ClearPluginCache(PortalSettings.Current.PortalId); } }
private NBrightInfo ValidateCartItem(int portalId, int userId, NBrightInfo cartItemInfo, Boolean removeZeroQtyItems = false) { #region "get cart values" cartItemInfo = NBrightBuyUtils.ProcessEventProvider(EventActions.ValidateCartItemBefore, cartItemInfo); var modelid = cartItemInfo.GetXmlProperty("genxml/modelid"); var prdid = cartItemInfo.GetXmlPropertyInt("genxml/productid"); var qty = cartItemInfo.GetXmlPropertyDouble("genxml/qty"); var lang = cartItemInfo.GetXmlProperty("genxml/lang"); if (removeZeroQtyItems && qty == 0) { return(null); // Remove zero qty item } if (lang == "") { lang = Utils.GetCurrentCulture(); } var prd = ProductUtils.GetProductData(prdid, lang); if (!prd.Exists || prd.Disabled) { return(null); //Invalid product remove from cart } // update product xml data on cart (product may have change via plugin so always replace) cartItemInfo.RemoveXmlNode("genxml/productxml"); // add entitytype for validation methods prd.Info.SetXmlProperty("genxml/entitytypecode", prd.Info.TypeCode); cartItemInfo.AddSingleNode("productxml", prd.Info.XMLData, "genxml"); var prdModel = prd.GetModel(modelid); if (prdModel == null) { return(null); // Invalid Model remove from cart } // check if dealer (for tax calc) if (NBrightBuyUtils.IsDealer()) { cartItemInfo.SetXmlProperty("genxml/isdealer", "True"); } else { cartItemInfo.SetXmlProperty("genxml/isdealer", "False"); } // check for price change var unitcost = prdModel.GetXmlPropertyDouble("genxml/textbox/txtunitcost"); var dealercost = prdModel.GetXmlPropertyDouble("genxml/textbox/txtdealercost"); var saleprice = prdModel.GetXmlPropertyDouble("genxml/textbox/txtsaleprice"); var dealersalecost = prdModel.GetXmlPropertyDouble("genxml/textbox/txtdealersale"); // use dynamic price is flagged in cartitem. if (cartItemInfo.GetXmlPropertyBool("genxml/dynamicpriceflag") && cartItemInfo.GetXmlProperty("genxml/dynamicprice") != "") { unitcost = cartItemInfo.GetXmlPropertyDouble("genxml/dynamicprice"); dealercost = cartItemInfo.GetXmlPropertyDouble("genxml/dynamicprice"); saleprice = cartItemInfo.GetXmlPropertyDouble("genxml/dynamicprice"); dealersalecost = cartItemInfo.GetXmlPropertyDouble("genxml/dynamicprice"); } // always make sale price best price if (unitcost > 0 && (unitcost < saleprice || saleprice <= 0)) { saleprice = unitcost; } // if we have a promoprice use it as saleprice (This is passed in via events provider like "Multi-Buy promotions") if (cartItemInfo.GetXmlPropertyDouble("genxml/promoprice") > 0 && cartItemInfo.GetXmlPropertyDouble("genxml/promoprice") < saleprice) { saleprice = cartItemInfo.GetXmlPropertyDouble("genxml/promoprice"); } // always assign the dealercost the best price. if (dealersalecost > 0 && dealersalecost < dealercost) { dealercost = dealersalecost; } if (saleprice > 0 && (saleprice < dealercost || dealercost <= 0)) { dealercost = saleprice; } if (unitcost > 0 && (unitcost < dealercost || dealercost <= 0)) { dealercost = unitcost; } // calc sell price // sellcost = the calculated cost of the item. var sellcost = unitcost; if (saleprice > 0 && saleprice < sellcost) { sellcost = saleprice; } if (NBrightBuyUtils.IsDealer()) { if (dealercost > 0 && dealercost < sellcost) { sellcost = dealercost; } } // -------------------------------------------- #endregion if (prdModel != null) { #region "Stock Control" var stockon = prdModel.GetXmlPropertyBool("genxml/checkbox/chkstockon"); var stocklevel = prdModel.GetXmlPropertyDouble("genxml/textbox/txtqtyremaining"); var minStock = prdModel.GetXmlPropertyDouble("genxml/textbox/txtqtyminstock"); if (minStock == 0) { minStock = StoreSettings.Current.GetInt("minimumstocklevel"); } var maxStock = prdModel.GetXmlPropertyDouble("genxml/textbox/txtqtystockset"); var weight = prdModel.GetXmlPropertyDouble("genxml/textbox/weight"); if (stockon) { stocklevel = stocklevel - minStock; stocklevel = stocklevel - prd.GetModelTransQty(modelid, _cartId); if (stocklevel < qty) { qty = stocklevel; if (qty <= 0) { qty = 0; cartItemInfo.SetXmlProperty("genxml/validatecode", "OUTOFSTOCK"); } else { cartItemInfo.SetXmlProperty("genxml/validatecode", "STOCKADJ"); } base.SetValidated(false); cartItemInfo.SetXmlPropertyDouble("genxml/qty", qty.ToString("")); } } #endregion #region "Addtional options costs" Double additionalCosts = 0; var optNods = cartItemInfo.XMLDoc.SelectNodes("genxml/options/*"); if (optNods != null) { var lp = 1; foreach (XmlNode nod in optNods) { var optid = nod.SelectSingleNode("optid"); if (optid != null) { var optvalueid = nod.SelectSingleNode("optvalueid"); if (optvalueid != null && optvalueid.InnerText != "False") { XmlNode optvalcostnod; if (optvalueid.InnerText == "True") { optvalcostnod = cartItemInfo.XMLDoc.SelectSingleNode("genxml/productxml/genxml/optionvalues[@optionid='" + optid.InnerText + "']/genxml/textbox/txtaddedcost"); } else { optvalcostnod = cartItemInfo.XMLDoc.SelectSingleNode("genxml/productxml/genxml/optionvalues/genxml[./hidden/optionvalueid='" + optvalueid.InnerText + "']/textbox/txtaddedcost"); } if (optvalcostnod != null) { var optvalcost = optvalcostnod.InnerText; if (Utils.IsNumeric(optvalcost)) { cartItemInfo.SetXmlPropertyDouble("genxml/options/option[" + lp + "]/optvalcost", optvalcost); var optvaltotal = Convert.ToDouble(optvalcost, CultureInfo.GetCultureInfo("en-US")) * qty; cartItemInfo.SetXmlPropertyDouble("genxml/options/option[" + lp + "]/optvaltotal", optvaltotal); additionalCosts += optvaltotal; } } else { cartItemInfo.SetXmlPropertyDouble("genxml/options/option[" + lp + "]/optvalcost", "0"); cartItemInfo.SetXmlPropertyDouble("genxml/options/option[" + lp + "]/optvaltotal", "0"); } } } lp += 1; } } if (qty > 0) // can't devide by zero { unitcost += (additionalCosts / qty); if (dealercost > 0) { dealercost += (additionalCosts / qty); // zero turns off } if (saleprice > 0) { saleprice += (additionalCosts / qty); // zero turns off } sellcost += (additionalCosts / qty); } #endregion var totalcost = qty * unitcost; var totalsellcost = qty * sellcost; var totalweight = weight * qty; cartItemInfo.SetXmlPropertyDouble("genxml/unitcost", unitcost); cartItemInfo.SetXmlPropertyDouble("genxml/dealercost", dealercost); cartItemInfo.SetXmlPropertyDouble("genxml/saleprice", saleprice); cartItemInfo.SetXmlPropertyDouble("genxml/totalweight", totalweight.ToString("")); cartItemInfo.SetXmlPropertyDouble("genxml/totalcost", totalcost); cartItemInfo.SetXmlPropertyDouble("genxml/totaldealerbonus", (totalcost - (qty * dealercost))); Double salediscount = 0; Double discountcodeamt = 0; Double totaldiscount = 0; //add update genxml/discountcodeamt var discountcode = PurchaseInfo.GetXmlProperty("genxml/extrainfo/genxml/textbox/promocode"); if (discountcode != "") { cartItemInfo = DiscountCodeInterface.UpdateItemPercentDiscountCode(PortalId, UserId, cartItemInfo, discountcode); discountcodeamt = cartItemInfo.GetXmlPropertyDouble("genxml/discountcodeamt"); if (discountcodeamt > 0) { PurchaseInfo.SetXmlProperty("genxml/discountprocessed", "False"); } } if (NBrightBuyUtils.IsDealer()) { salediscount = (unitcost - dealercost); } else { salediscount = (unitcost - saleprice); } totaldiscount = (salediscount * qty) + discountcodeamt; // add on any promo code amount if (totaldiscount < 0) { totaldiscount = 0; } // if we have a promodiscount use it if (cartItemInfo.GetXmlPropertyDouble("genxml/promodiscount") > 0) { totaldiscount = cartItemInfo.GetXmlPropertyDouble("genxml/promodiscount"); totalcost = totalcost - totaldiscount; if (totalcost < 0) { totalcost = 0; } cartItemInfo.SetXmlPropertyDouble("genxml/appliedtotalcost", totalcost); } cartItemInfo.SetXmlPropertyDouble("genxml/totaldiscount", totaldiscount); // if product is on sale then we need to display the sale price in the cart, and any discount codes don;t show at this cart item level, only on the order total. cartItemInfo.SetXmlPropertyDouble("genxml/appliedtotalcost", totalsellcost); cartItemInfo.SetXmlPropertyDouble("genxml/appliedcost", sellcost); // calc tax for item var taxproviderkey = PurchaseInfo.GetXmlProperty("genxml/hidden/taxproviderkey"); var taxprov = TaxInterface.Instance(taxproviderkey); if (taxprov != null) { var nbi = (NBrightInfo)cartItemInfo.Clone(); cartItemInfo.SetXmlPropertyDouble("genxml/taxcost", taxprov.CalculateItemTax(nbi)); } } cartItemInfo = NBrightBuyUtils.ProcessEventProvider(EventActions.ValidateCartItemAfter, cartItemInfo); return(cartItemInfo); }
private Boolean CheckSecurity(NBrightInfo pluginData) { if (pluginData.GetXmlPropertyBool("genxml/checkbox/hidden")) return false; var roles = pluginData.GetXmlProperty("genxml/textbox/roles"); if (roles.Trim() == "") return true; if (UserInfo.IsSuperUser) return true; if (UserInfo.IsInRole("Administrator")) return true; var rlist = roles.Split(','); foreach (var r in rlist) { if (UserInfo.IsInRole(r)) return true; } return false; }
public override NBrightInfo Calculate(NBrightInfo cartInfo) { var enableShippingTax = _info.GetXmlPropertyBool("genxml/checkbox/enableshippingtax"); var shippingTaxRate = _info.GetXmlPropertyDouble("genxml/textbox/shippingtaxrate"); // return taxtype, 1 = included in cost, 2 = not included in cost, 3 = no tax, 4 = tax included in cost, but calculate to zero. cartInfo.SetXmlPropertyDouble("genxml/taxtype", _taxType); if (_taxType == "3" || _taxType == "4") // no tax calculation { cartInfo.SetXmlPropertyDouble("genxml/taxcost", 0); cartInfo.SetXmlPropertyDouble("genxml/appliedtax", 0); return(cartInfo); } var rateDic = GetRates(); if (!rateDic.Any()) { return(cartInfo); } // loop through each item and calc the tax for each. var nodList = cartInfo.XMLDoc.SelectNodes("genxml/items/*"); if (nodList != null) { Double taxtotal = 0; foreach (XmlNode nod in nodList) { var nbi = new NBrightInfo(); nbi.XMLData = nod.OuterXml; taxtotal += CalculateItemTax(nbi, rateDic); } if (enableShippingTax && shippingTaxRate > 0) { var isDealer = false; // default until dealer shipping cost implemented taxtotal += CalculateShippingTax(cartInfo, shippingTaxRate, isDealer); } cartInfo.SetXmlPropertyDouble("genxml/taxcost", taxtotal); if (_taxType == "1") { cartInfo.SetXmlPropertyDouble("genxml/appliedtax", 0); // tax already in total, so don't apply any more tax. } if (_taxType == "2") { cartInfo.SetXmlPropertyDouble("genxml/appliedtax", taxtotal); } var taxcountry = cartInfo.GetXmlProperty("genxml/billaddress/genxml/dropdownlist/country"); var storecountry = StoreSettings.Current.Get("storecountry"); var valideutaxcountrycode = _info.GetXmlProperty("genxml/textbox/valideutaxcountrycode"); var isvalidEU = false; valideutaxcountrycode = "," + valideutaxcountrycode.ToUpper().Replace(" ", "") + ","; if ((valideutaxcountrycode.Contains("," + taxcountry.ToUpper().Replace(" ", "") + ","))) { isvalidEU = true; } // Check for EU tax number. var enabletaxnumber = _info.GetXmlPropertyBool("genxml/checkbox/enabletaxnumber"); if (enabletaxnumber) { var taxnumber = cartInfo.GetXmlProperty("genxml/billaddress/genxml/textbox/taxnumber").Trim(); if (storecountry != taxcountry && taxnumber != "") { // not matching merchant country, so remove tax if (_taxType == "1") { cartInfo.SetXmlPropertyDouble("genxml/taxcost", taxtotal * -1); cartInfo.SetXmlPropertyDouble("genxml/appliedtax", taxtotal * -1); } if (_taxType == "2") { cartInfo.SetXmlPropertyDouble("genxml/taxcost", 0); cartInfo.SetXmlPropertyDouble("genxml/appliedtax", 0); } } } // Check for country. var enabletaxcountry = _info.GetXmlPropertyBool("genxml/checkbox/enabletaxcountry"); if (enabletaxcountry) { if (taxcountry != "") { if (taxcountry != storecountry && !isvalidEU) { // not matching merchant country, so remove tax if (_taxType == "1") { cartInfo.SetXmlPropertyDouble("genxml/taxcost", taxtotal * -1); cartInfo.SetXmlPropertyDouble("genxml/appliedtax", taxtotal * -1); } if (_taxType == "2") { cartInfo.SetXmlPropertyDouble("genxml/taxcost", 0); cartInfo.SetXmlPropertyDouble("genxml/appliedtax", 0); } } } } // check for region exempt (in same country) var taxexemptregions = _info.GetXmlProperty("genxml/textbox/taxexemptregions"); if (taxexemptregions != "" && taxcountry == storecountry) { taxexemptregions = "," + taxexemptregions.ToUpper().Replace(" ", "") + ","; var taxregioncode = cartInfo.GetXmlProperty("genxml/billaddress/genxml/dropdownlist/region").Trim(); if (taxregioncode == "") { taxregioncode = cartInfo.GetXmlProperty("genxml/billaddress/genxml/textbox/txtregion").Trim(); } if (taxregioncode != "") { if (!taxexemptregions.Contains("," + taxregioncode.ToUpper().Replace(" ", "") + ",")) { // not matching merchant region, so remove tax if (_taxType == "1") { cartInfo.SetXmlPropertyDouble("genxml/taxcost", taxtotal * -1); cartInfo.SetXmlPropertyDouble("genxml/appliedtax", taxtotal * -1); } if (_taxType == "2") { cartInfo.SetXmlPropertyDouble("genxml/taxcost", 0); cartInfo.SetXmlPropertyDouble("genxml/appliedtax", 0); } } } } } return(cartInfo); }
public static string CalcGroupPromoItem(NBrightInfo p) { var objCtrl = new NBrightBuyController(); var typeselect = p.GetXmlProperty("genxml/radiobuttonlist/typeselect"); var catgroupid = p.GetXmlProperty("genxml/dropdownlist/catgroupid"); var propgroupid = p.GetXmlProperty("genxml/dropdownlist/propgroupid"); var promoname = p.GetXmlProperty("genxml/textbox/name"); var amounttype = p.GetXmlProperty("genxml/radiobuttonlist/amounttype"); var amount = p.GetXmlPropertyDouble("genxml/textbox/amount"); var validfrom = p.GetXmlProperty("genxml/textbox/validfrom"); var validuntil = p.GetXmlProperty("genxml/textbox/validuntil"); var overwrite = p.GetXmlPropertyBool("genxml/checkbox/overwrite"); var disabled = p.GetXmlPropertyBool("genxml/checkbox/disabled"); var lastcalculated = p.GetXmlProperty("genxml/hidden/lastcalculated"); var whichprice = p.GetXmlPropertyInt("genxml/radiobuttonlist/whichprice"); var runfreq = p.GetXmlPropertyInt("genxml/radiobuttonlist/runfreq"); if (!disabled) { var portalsettings = NBrightDNN.DnnUtils.GetPortalSettings(p.PortalId); var lang = portalsettings.DefaultLanguage; var prdList = new List <NBrightInfo>(); if (typeselect == "all") { prdList = objCtrl.GetList(p.PortalId, -1, "PRD"); } else { CategoryData gCat; var groupid = catgroupid; if (typeselect != "cat") { groupid = propgroupid; } gCat = CategoryUtils.GetCategoryData(groupid, lang); if (gCat != null) { prdList = gCat.GetAllArticles(); } } var runcalc = true; if (runfreq == 1 || runfreq == 3) // run freq is date range { if (runfreq == 3) { // run constantly, set end date to +100 year validfrom = DateTime.Now.AddYears(-1).ToString("s"); validuntil = DateTime.Now.AddYears(100).ToString("s"); } // run date range if (Utils.IsDate(lastcalculated)) { if (Convert.ToDateTime(lastcalculated) >= p.ModifiedDate) { runcalc = false; // only run if changed } if (DateTime.Now.Date > Convert.ToDateTime(lastcalculated).Date.AddDays(1)) { runcalc = true; // every day just after midnight. (for site performace) } } if (Utils.IsDate(validuntil)) { if (DateTime.Now.Date > Convert.ToDateTime(validuntil)) { runcalc = true; // need to disable the promo if passed date } } if ((runcalc) && Utils.IsDate(validfrom) && Utils.IsDate(validuntil)) { var dteF = Convert.ToDateTime(validfrom).Date; var dteU = Convert.ToDateTime(validuntil).Date; foreach (var prd in prdList) { var productid = prd.ParentItemId; if (typeselect == "all") { productid = prd.ItemID; } if (DateTime.Now.Date >= dteF && DateTime.Now.Date <= dteU) { // CALC Promo CalcProductSalePrice(p.PortalId, productid, amounttype, amount, p.ItemID, whichprice, overwrite); } if (DateTime.Now.Date > dteU) { // END Promo RemoveProductPromoData(p.PortalId, productid, p.ItemID); } ProductUtils.RemoveProductDataCache(p.PortalId, productid); var productData = ProductUtils.GetProductData(productid, p.PortalId, lang); productData.Save(); // recalc any new prices. } if (DateTime.Now.Date > dteU) { // END Promo p.SetXmlProperty("genxml/checkbox/disabled", "True"); } } } if (runfreq == 2) // run Once, do update and disable promo. { foreach (var prd in prdList) { var productid = prd.ParentItemId; if (typeselect == "all") { productid = prd.ItemID; } // CALC Promo CalcProductSalePrice(p.PortalId, productid, amounttype, amount, p.ItemID, whichprice, overwrite); ProductUtils.RemoveProductDataCache(p.PortalId, productid); var productData = ProductUtils.GetProductData(productid, p.PortalId, lang); productData.Save(); // recalc any new prices. } p.SetXmlProperty("genxml/checkbox/disabled", "True"); } if (runfreq == 4) // remove { foreach (var prd in prdList) { var productid = prd.ParentItemId; if (typeselect == "all") { productid = prd.ItemID; } RemoveProductPromoData(p.PortalId, productid, p.ItemID); ProductUtils.RemoveProductDataCache(p.PortalId, productid); var productData = ProductUtils.GetProductData(productid, p.PortalId, lang); productData.Save(); // recalc any new prices. } p.SetXmlProperty("genxml/checkbox/disabled", "True"); } p.SetXmlProperty("genxml/hidden/lastcalculated", DateTime.Now.AddSeconds(10).ToString("O")); // Add 10 sec to time so we don't get exact clash with update time. objCtrl.Update(p); } return("OK"); }
public static string CalcMultiBuyPromoItem(NBrightInfo p) { var objCtrl = new NBrightBuyController(); var propgroupid = p.GetXmlPropertyInt("genxml/dropdownlist/propbuy"); var promoname = p.GetXmlProperty("genxml/textbox/name"); var validfrom = p.GetXmlProperty("genxml/textbox/validfrom"); var validuntil = p.GetXmlProperty("genxml/textbox/validuntil"); var disabled = p.GetXmlPropertyBool("genxml/checkbox/disabled"); var lastcalculated = p.GetXmlProperty("genxml/hidden/lastcalculated"); if (!disabled) { var portalsettings = NBrightDNN.DnnUtils.GetPortalSettings(p.PortalId); var lang = portalsettings.DefaultLanguage; var runcalc = true; if (Utils.IsDate(lastcalculated)) { if (Convert.ToDateTime(lastcalculated) >= p.ModifiedDate) { runcalc = false; // only run if changed } if (DateTime.Now.Date > Convert.ToDateTime(lastcalculated).Date.AddDays(1)) { runcalc = true; // every day just after midnight. (for site performace) } } if (Utils.IsDate(validuntil)) { if (DateTime.Now.Date > Convert.ToDateTime(validuntil)) { runcalc = true; // need to disable the promo if passed date } } if ((runcalc) && Utils.IsDate(validfrom) && Utils.IsDate(validuntil)) { var dteF = Convert.ToDateTime(validfrom).Date; var dteU = Convert.ToDateTime(validuntil).Date; CategoryData gCat; gCat = CategoryUtils.GetCategoryData(propgroupid, lang); var prdList = gCat.GetAllArticles(); foreach (var prd in prdList) { if (DateTime.Now.Date >= dteF && DateTime.Now.Date <= dteU) { // CALC Promo FlagProductMultiBuy(p.PortalId, prd.ParentItemId, promoname, p.ItemID, "PROMOMULTIBUY", dteF, dteU); } if (DateTime.Now.Date > dteU) { // END Promo RemoveProductPromoData(p.PortalId, prd.ParentItemId, p.ItemID); p.SetXmlProperty("genxml/checkbox/disabled", "True"); objCtrl.Update(p); } ProductUtils.RemoveProductDataCache(p.PortalId, prd.ParentItemId); var productData = ProductUtils.GetProductData(prd.ParentItemId, p.PortalId, lang); productData.Save(); // recalc any new prices. } p.SetXmlProperty("genxml/hidden/lastcalculated", DateTime.Now.AddSeconds(10).ToString("O")); // Add 10 sec to time so we don't get exact clash with update time. objCtrl.Update(p); } } return("OK"); }
private static void CalcProductSalePrice(int portalid, int productId, string amounttype, double amount, int promoid, int whichprice, bool overwrite) { var cultureList = DnnUtils.GetCultureCodeList(portalid); var objCtrl = new NBrightBuyController(); var prdData = objCtrl.GetData(productId); var nodList = prdData.XMLDoc.SelectNodes("genxml/models/genxml"); if (nodList != null) { prdData.SetXmlProperty("genxml/hidden/promoflag", "True"); // set flag, so we can identify products with promo for product save event removal. if (prdData.GetXmlProperty("genxml/promo") == "") { prdData.SetXmlProperty("genxml/promo", ""); } var lp = 1; foreach (XmlNode nod in nodList) { var currentpromoid = GetCurrentPromoId(prdData, whichprice, lp); var nbi = new NBrightInfo(); nbi.XMLData = nod.OuterXml; var disablesale = nbi.GetXmlPropertyBool("genxml/checkbox/chkdisablesale"); var disabledealer = nbi.GetXmlPropertyBool("genxml/checkbox/chkdisabledealer"); var unitcost = nbi.GetXmlPropertyDouble("genxml/textbox/txtunitcost"); var dealercost = nbi.GetXmlPropertyDouble("genxml/textbox/txtdealercost"); Double newamt = 0; Double newdealersaleamt = 0; Double newdealeramt = 0; if (amounttype == "1") { newamt = unitcost - amount; newdealersaleamt = dealercost - amount; } else { newamt = unitcost - ((unitcost / 100) * amount); newdealersaleamt = dealercost - ((dealercost / 100) * amount); } newdealeramt = newamt; if (newamt < 0) { newamt = 0; } if (newdealersaleamt < 0) { newdealersaleamt = 0; } var currentprice = GetCurrentPromoPrice(prdData, whichprice, lp); if (!overwrite) { if (currentprice == 0) { overwrite = true; } if (currentpromoid == promoid) { overwrite = true; } } if (overwrite) { switch (whichprice) { case 1: prdData.SetXmlPropertyDouble("genxml/models/genxml[" + lp + "]/textbox/txtsaleprice", newamt); prdData.SetXmlProperty("genxml/promo/salepriceid" + lp, promoid.ToString()); break; case 2: prdData.SetXmlPropertyDouble("genxml/models/genxml[" + lp + "]/textbox/txtdealercost", newdealeramt); prdData.SetXmlProperty("genxml/promo/dealercostid" + lp, promoid.ToString()); break; case 3: prdData.SetXmlPropertyDouble("genxml/models/genxml[" + lp + "]/textbox/txtdealersale", newdealersaleamt); prdData.SetXmlProperty("genxml/promo/dealersaleid" + lp, promoid.ToString()); break; case 4: prdData.SetXmlPropertyDouble("genxml/models/genxml[" + lp + "]/textbox/txtdealersale", newdealersaleamt); prdData.SetXmlProperty("genxml/promo/dealersaleid" + lp, promoid.ToString()); prdData.SetXmlPropertyDouble("genxml/models/genxml[" + lp + "]/textbox/txtsaleprice", newamt); prdData.SetXmlProperty("genxml/promo/salepriceid" + lp, promoid.ToString()); break; default: prdData.SetXmlPropertyDouble("genxml/models/genxml[" + lp + "]/textbox/txtsaleprice", newamt); prdData.SetXmlProperty("genxml/promo/salepriceid" + lp, promoid.ToString()); break; } } if (disablesale) { prdData.SetXmlPropertyDouble("genxml/models/genxml[" + lp + "]/textbox/txtsaleprice", 0); prdData.RemoveXmlNode("genxml/promo/salepriceid" + lp); } if (disabledealer) { prdData.SetXmlPropertyDouble("genxml/models/genxml[" + lp + "]/textbox/txtdealercost", 0); prdData.RemoveXmlNode("genxml/promo/dealercostid" + lp); prdData.SetXmlPropertyDouble("genxml/models/genxml[" + lp + "]/textbox/txtdealersale", 0); prdData.RemoveXmlNode("genxml/promo/dealersaleid" + lp); } lp += 1; } objCtrl.Update(prdData); foreach (var lang in cultureList) { var promodesc = ""; var p = objCtrl.GetDataLang(promoid, lang); if (p != null) { promodesc = p.GetXmlProperty("genxml/textbox/description"); } var prdDataLang = objCtrl.GetDataLang(productId, lang); if (prdDataLang != null) { prdDataLang.SetXmlProperty("genxml/hidden/promodesc", promodesc); objCtrl.Update(prdDataLang); } } } }
public static NBrightInfo CalcQtyPromoItem(NBrightInfo p, NBrightInfo cartItemInfo) { var objCtrl = new NBrightBuyController(); var typeselect = p.GetXmlProperty("genxml/radiobuttonlist/typeselect"); var catgroupid = p.GetXmlProperty("genxml/dropdownlist/catgroupid"); var propgroupid = p.GetXmlProperty("genxml/dropdownlist/propgroupid"); var promoname = p.GetXmlProperty("genxml/textbox/name"); var amounttype = p.GetXmlProperty("genxml/radiobuttonlist/amounttype"); var amount = p.GetXmlPropertyDouble("genxml/textbox/amount"); var overwrite = p.GetXmlPropertyBool("genxml/checkbox/overwrite"); var disabled = p.GetXmlPropertyBool("genxml/checkbox/disabled"); var rangeList = p.GetXmlProperty("genxml/textbox/range"); if (!disabled) { var productid = cartItemInfo.GetXmlPropertyInt("genxml/productid"); if (productid > 0) { var prodData = new ProductData(productid, Utils.GetCurrentCulture()); if (prodData.Exists) { var groupid = catgroupid; if (typeselect == "prop") { groupid = propgroupid; } var gCat = CategoryUtils.GetCategoryData(groupid, Utils.GetCurrentCulture()); if (gCat == null) { return(cartItemInfo); } if (prodData.HasProperty(gCat.CategoryRef) || prodData.IsInCategory(gCat.CategoryRef)) { var runcalc = true; // build range Data var rangeData = new List <RangeItem>(); 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.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); } } } var unitcost = cartItemInfo.GetXmlPropertyDouble("genxml/unitcost"); var promoprice = cartItemInfo.GetXmlPropertyDouble("genxml/promoprice"); var rangeValue = cartItemInfo.GetXmlPropertyDouble("genxml/qty"); var basecost = unitcost; foreach (var i in rangeData) { if (rangeValue >= i.RangeLow && rangeValue < i.RangeHigh) { double newsaleprice = 0; if (amounttype == "1") { // percentage discount newsaleprice = Math.Round(basecost - ((basecost / 100) * i.Cost), 4); } else { // amount discount newsaleprice = basecost - i.Cost; if (newsaleprice < 0) { newsaleprice = 0; } } cartItemInfo.SetXmlPropertyDouble("genxml/promoprice", newsaleprice); } } } } } } return(cartItemInfo); }
public override Double CalculateItemTax(NBrightInfo cartItemInfo) { var info = ProviderUtils.GetProviderSettings("tax"); var taxtype = info.GetXmlProperty("genxml/radiobuttonlist/taxtype"); if (taxtype == "3") return 0; var rateDic = GetRates(); if (!rateDic.Any()) return 0; // loop through each item and calc the tax for each. Double taxtotal = 0; var totalcost = cartItemInfo.GetXmlPropertyDouble("genxml/totalcost"); if (cartItemInfo.GetXmlPropertyBool("genxml/isdealer")) totalcost = cartItemInfo.GetXmlPropertyDouble("genxml/totaldealercost"); var taxratecode = cartItemInfo.GetXmlProperty("genxml/taxratecode"); if (taxratecode == "") taxratecode = "0"; if (!rateDic.ContainsKey(taxratecode)) taxratecode = "0"; Double taxrate = 0; if (rateDic.ContainsKey(taxratecode)) taxrate = rateDic[taxratecode]; // Can happen is no default tax added. if (taxtype == "1") // included in unit price { taxtotal += totalcost - ((totalcost / (100 + taxrate)) * 100); } if (taxtype == "2") // NOT included in unit price { taxtotal += (totalcost / 100) * taxrate; } return Math.Round(taxtotal, 2); }
public static string CalcGroupPromoItem(NBrightInfo p) { var objCtrl = new NBrightBuyController(); var typeselect = p.GetXmlProperty("genxml/radiobuttonlist/typeselect"); var catgroupid = p.GetXmlProperty("genxml/dropdownlist/catgroupid"); var propgroupid = p.GetXmlProperty("genxml/dropdownlist/propgroupid"); var promoname = p.GetXmlProperty("genxml/textbox/name"); var amounttype = p.GetXmlProperty("genxml/radiobuttonlist/amounttype"); var amount = p.GetXmlPropertyDouble("genxml/textbox/amount"); var validfrom = p.GetXmlProperty("genxml/textbox/validfrom"); var validuntil = p.GetXmlProperty("genxml/textbox/validuntil"); var overwrite = p.GetXmlPropertyBool("genxml/checkbox/overwrite"); var disabled = p.GetXmlPropertyBool("genxml/checkbox/disabled"); var lastcalculated = p.GetXmlProperty("genxml/hidden/lastcalculated"); if (!disabled) { var runcalc = true; if (Utils.IsDate(lastcalculated)) { if (Convert.ToDateTime(lastcalculated) >= p.ModifiedDate) runcalc = false; // only run if changed if (DateTime.Now.Date > Convert.ToDateTime(lastcalculated).Date.AddDays(1)) runcalc = true; // every day just after midnight. (for site performace) } if (Utils.IsDate(validuntil)) { if (DateTime.Now.Date > Convert.ToDateTime(validuntil)) runcalc = true; // need to disable the promo if passed date } if ((runcalc) && Utils.IsDate(validfrom) && Utils.IsDate(validuntil)) { var dteF = Convert.ToDateTime(validfrom).Date; var dteU = Convert.ToDateTime(validuntil).Date; CategoryData gCat; var groupid = catgroupid; if (typeselect != "cat") groupid = propgroupid; gCat = CategoryUtils.GetCategoryData(groupid, Utils.GetCurrentCulture()); var prdList = gCat.GetAllArticles(); foreach (var prd in prdList) { if (DateTime.Now.Date >= dteF && DateTime.Now.Date <= dteU) { // CALC Promo CalcProductSalePrice(p.PortalId, prd.ParentItemId, amounttype, amount, promoname, p.ItemID, overwrite,dteF,dteU); } if (DateTime.Now.Date > dteU) { // END Promo RemoveProductPromoData(p.PortalId, prd.ParentItemId, p.ItemID); p.SetXmlProperty("genxml/checkbox/disabled", "True"); objCtrl.Update(p); } ProductUtils.RemoveProductDataCache(p.PortalId, prd.ParentItemId); } p.SetXmlProperty("genxml/hidden/lastcalculated", DateTime.Now.AddSeconds(10).ToString("O")); // Add 10 sec to time so we don't get exact clash with update time. objCtrl.Update(p); } } return "OK"; }
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; }