Skip to content

Commit

Permalink
Merge pull request #189 from DNNMonster/bugfix/portal-id-usage
Browse files Browse the repository at this point in the history
Enhance portal id usage
  • Loading branch information
leedavi authored Aug 31, 2021
2 parents 9ed4af1 + 746c6ea commit 60da642
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 59 deletions.
7 changes: 6 additions & 1 deletion Components/GrpCatController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -338,10 +338,15 @@ public List<GroupCategoryData> GetProductCategories(int productid, String groupr
notcat = "cat";
}

var joinItems = (from d1 in GrpCategoryList
var joinItems = new List<GroupCategoryData>();
if (GrpCategoryList != null)
{
joinItems = (from d1 in GrpCategoryList
join d2 in catxrefList on d1.categoryid equals d2.XrefItemId
where (d1.grouptyperef == groupref || groupref == "") && d1.grouptyperef != notcat
select d1).OrderBy(d1 => d1.grouptyperef).ThenBy(d1 => d1.breadcrumb).ToList<GroupCategoryData>();

}
return joinItems;
}

Expand Down
25 changes: 15 additions & 10 deletions Components/NBrightBuyController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -915,28 +915,33 @@ private static NBrightInfo UpdateLangNodeFields(String xmlname, NBrightInfo base
return dlang;
}

/// <summary>
/// Get current portal StoreSettings
/// </summary>
/// <returns></returns>
public static StoreSettings GetCurrentPortalData()
{
public static StoreSettings GetPortalData(int portalId)
{
StoreSettings objPortalSettings = null;
if (HttpContext.Current != null)
{
// build StoreSettings and place in httpcontext
if (HttpContext.Current.Items["NBBStoreSettings" + PortalSettings.Current.PortalId.ToString("")] == null)
if (HttpContext.Current.Items["NBBStoreSettings" + portalId.ToString()] == null)
{
HttpContext.Current.Items.Add("NBBStoreSettings" + PortalSettings.Current.PortalId.ToString(""),GetStaticStoreSettings(PortalSettings.Current.PortalId));
HttpContext.Current.Items.Add("NBBStoreSettings" + portalId.ToString(), GetStaticStoreSettings(portalId));
}
objPortalSettings = (StoreSettings)HttpContext.Current.Items["NBBStoreSettings" + PortalSettings.Current.PortalId.ToString("")];
objPortalSettings = (StoreSettings)HttpContext.Current.Items["NBBStoreSettings" + portalId.ToString()];
}
else
{
// capture all to ensure we pass something.
objPortalSettings = GetStaticStoreSettings(PortalSettings.Current.PortalId);
objPortalSettings = GetStaticStoreSettings(portalId);
}
return objPortalSettings;
}

/// <summary>
/// Get current portal StoreSettings
/// </summary>
/// <returns></returns>
public static StoreSettings GetCurrentPortalData()
{
return GetPortalData(PortalSettings.Current.PortalId);
}

/// <summary>
Expand Down
43 changes: 25 additions & 18 deletions Components/Product/ProductData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -444,14 +444,15 @@ public NBrightInfo GetOptionValue(String optionid, String optionvalueid)
/// <summary>
/// Select categories linked to product, by groupref
/// </summary>
/// <param name="portalId"></param>
/// <param name="groupref">groupref for select, "" = all, "cat"= Category only, "!cat" = all non-category, "{groupref}"=this group only</param>
/// <param name="cascade">get all cascade records to get all parent categories</param>
/// <returns></returns>
public List<GroupCategoryData> GetCategories(String groupref = "", Boolean cascade = false)
public List<GroupCategoryData> GetCategories(int portalId, String groupref = "", Boolean cascade = false)
{
if (Info == null) return new List<GroupCategoryData>(); // stop throwing an error no product exists,

var objGrpCtrl = new GrpCatController(_lang);
var objGrpCtrl = new GrpCatController(_lang, portalId);
var catl = objGrpCtrl.GetProductCategories(Info.ItemID, groupref, cascade);
if (Utils.IsNumeric(DataRecord.GetXmlProperty("genxml/defaultcatid")) && catl.Count > 0)
{
Expand All @@ -468,6 +469,19 @@ public List<GroupCategoryData> GetCategories(String groupref = "", Boolean casca
return catl;
}


/// <summary>
/// Select categories linked to product, by groupref
/// </summary>
/// <param name="groupref">groupref for select, "" = all, "cat"= Category only, "!cat" = all non-category, "{groupref}"=this group only</param>
/// <param name="cascade">get all cascade records to get all parent categories</param>
/// <returns></returns>
public List<GroupCategoryData> GetCategories(String groupref = "", Boolean cascade = false)
{
var portalId = PortalSettings.Current.PortalId;
return GetCategories(portalId, groupref, cascade);
}

/// <summary>
/// Select properties linked to product, by groupref
/// </summary>
Expand Down Expand Up @@ -689,6 +703,7 @@ public void Save(bool triggerevent, bool newrecord)
DataRecord = objCtrl.Get(productid);
DataLangRecord = objCtrl.Get(plangid);
}

}

private void UpdateDisplayCalcPrices()
Expand Down Expand Up @@ -1744,6 +1759,7 @@ public int Validate()
}
lp += 1;
}

//Fix document paths
lp = 1;
foreach (var d in Docs)
Expand Down Expand Up @@ -1794,7 +1810,7 @@ public int Validate()
}

// remove duplicate category xrefs.
var catlist = GetCategories();
var catlist = GetCategories(_portalId);
foreach (var c in catlist)
{
var l = objCtrl.GetList(_portalId, -1, "CATXREF", " and NB1.ParentItemId = " + Info.ItemID.ToString("") + " and NB1.XrefItemId = " + c.categoryid.ToString(""));
Expand Down Expand Up @@ -1835,6 +1851,7 @@ public int Validate()
objCtrl.Delete(c.ItemID);
errorcount += 1;
}

// remove catcascade record that have no catxref record for the product.
var caslist = new List<int>();
var catcascadelist = objCtrl.GetList(_portalId, -1, "CATCASCADE", " and nb1.ParentItemId = '" + Info.ItemID + "' ");
Expand All @@ -1843,10 +1860,10 @@ public int Validate()
caslist.Add(n.XrefItemId);
}

var catlist2 = GetCategories();
var catlist2 = GetCategories(_portalId);
if (catlist2.Any())
{
var objGrpCtrl = new GrpCatController(_lang, true);
var objGrpCtrl = new GrpCatController(_lang, _portalId, true);
foreach (var cat in catlist2)
{
var parentcats = objGrpCtrl.GetCategory(cat.categoryid);
Expand Down Expand Up @@ -1876,10 +1893,9 @@ public int Validate()
}
}



// update shared product if flagged
if (StoreSettings.Current.GetBool("shareproducts") && DataRecord.PortalId >= 0)
StoreSettings storeSettings = (System.Web.HttpContext.Current != null) ? StoreSettings.Current : new StoreSettings(_portalId);
if (storeSettings.GetBool("shareproducts") && DataRecord.PortalId >= 0)
{
upd = true;
DataRecord.PortalId = -1;
Expand All @@ -1889,7 +1905,7 @@ public int Validate()
}
}

// check if we have empty model name ()
// check if we have empty model name
var modellp = 1;
foreach (var m in Models)
{
Expand Down Expand Up @@ -1975,13 +1991,11 @@ public int Validate()
}
}


return errorcount;
}

public int Copy()
{

var objCtrl = new NBrightBuyController();

//Copy Base record
Expand Down Expand Up @@ -2083,7 +2097,6 @@ public void FillEmptyLanguageFields()
}
}


// models
var nodList1 = DataLangRecord.XMLDoc.SelectNodes("genxml/models/genxml");
if (nodList1 != null)
Expand Down Expand Up @@ -2214,15 +2227,11 @@ public void FillEmptyLanguageFields()
}
}


public void OutputDebugFile(String filePathName)
{
Info.XMLDoc.Save(filePathName);
}




#endregion

#region " private functions"
Expand Down Expand Up @@ -2311,7 +2320,6 @@ private void LoadData(int productId, Boolean hydrateLists = true)

private int AddNew()
{

var nbi = new NBrightInfo(true);
if (StoreSettings.Current.Get("shareproducts") == "True") // option in storesetting to share products created here across all portals.
_portalId = -1;
Expand Down Expand Up @@ -2468,7 +2476,6 @@ public Double GetDealerSalePriceDouble()
return price;
}


private bool CheckClientFileUpload()
{
return Info.GetXmlPropertyBool("genxml/checkbox/chkfileupload");
Expand Down
25 changes: 22 additions & 3 deletions Components/Product/ProductUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -455,29 +455,48 @@ private static List<string> BuildModelCodes(List<NBrightInfo> optList, int lpPos
return mcList;
}


/// <summary>
/// Get ProductData class with cacheing
/// </summary>
/// <param name="productId"></param>
/// <param name="portalId"></param>
/// <param name="lang"></param>
/// <param name="hydrateLists"></param>
/// <param name="typeCode">Typecode of record default "PRD"</param>
/// <param name="typeLangCode">Langauge Typecode of record default "PRDLANG"</param>
/// <returns></returns>
public static ProductData GetProductData(int productId, String lang, Boolean hydrateLists = true, String typeCode = "PRD")
public static ProductData GetProductData(int productId, int portalId, String lang, Boolean hydrateLists = true, String typeCode = "PRD")
{
ProductData prdData;
var cacheKey = "NBSProductData*" + productId.ToString("") + "*" + lang;
prdData = (ProductData)Utils.GetCache(cacheKey);
if ((prdData == null) || (productId == -1))
{
prdData = new ProductData(productId, lang, hydrateLists, typeCode);
prdData = new ProductData(productId, portalId, lang, hydrateLists, typeCode);
Utils.SetCache(cacheKey, prdData);
}
return prdData;
}


/// <summary>
/// Get ProductData class with cacheing
/// </summary>
/// <param name="productId"></param>
/// <param name="lang"></param>
/// <param name="hydrateLists"></param>
/// <param name="typeCode">Typecode of record default "PRD"</param>
/// <param name="typeLangCode">Langauge Typecode of record default "PRDLANG"</param>
/// <returns></returns>
public static ProductData GetProductData(int productId, String lang, Boolean hydrateLists = true, String typeCode = "PRD")
{
if (Utils.IsNumeric(productId))
{
return GetProductData(Convert.ToInt32(productId), PortalSettings.Current.PortalId, lang, hydrateLists, typeCode);
}
return null;
}

public static ProductData GetProductData(String productId, String lang, Boolean hydrateLists = true)
{
if (Utils.IsNumeric(productId))
Expand Down
26 changes: 7 additions & 19 deletions Providers/PromoProvider/PromoProvider.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Web.Hosting;
using System.Web.UI.WebControls;
using System.Xml;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Entities.Portals;
using NBrightCore.common;
using NBrightCore.common;
using NBrightDNN;
using Nevoweb.DNN.NBrightBuy.Components;
using System;
using System.Collections.Generic;

namespace Nevoweb.DNN.NBrightBuy.Providers.PromoProvider
{
Expand All @@ -20,17 +12,14 @@ public override string DoWork(int portalId)
{
return PromoUtils.CalcGroupPromo(portalId);
}

}


public class MultiBuyPromoScheudler : Components.Interfaces.SchedulerInterface
{
public override string DoWork(int portalId)
{
return PromoUtils.CalcMultiBuyPromo(portalId);
}

}

public class CalcPromo : Components.Interfaces.PromoInterface
Expand Down Expand Up @@ -59,7 +48,7 @@ public override NBrightInfo CalculatePromotion(int portalId, NBrightInfo cartInf
var promoData = objCtrl.GetData(promoid);
if (promoData != null)
{
//NOTE: WE nedd to process disabld promotions so they can be removed from cart
//NOTE: WE need to process disabld promotions so they can be removed from cart

var buyqty = promoData.GetXmlPropertyInt("genxml/textbox/buyqty");
var validfrom = promoData.GetXmlProperty("genxml/textbox/validfrom");
Expand All @@ -69,8 +58,7 @@ public override NBrightInfo CalculatePromotion(int portalId, NBrightInfo cartInf
var amounttype = promoData.GetXmlProperty("genxml/radiobuttonlist/amounttype");
var amount = promoData.GetXmlPropertyDouble("genxml/textbox/amount");


// Applied discount to this single cart item
// Applied discount to this single cart item
if (!promoData.GetXmlPropertyBool("genxml/checkbox/disabled") && cartItemInfo.GetXmlPropertyInt("genxml/qty") >= buyqty && Utils.IsDate(validfrom) && Utils.IsDate(validuntil)) // check we have correct qty to activate promo
{
var dteF = Convert.ToDateTime(validfrom).Date;
Expand Down Expand Up @@ -155,7 +143,7 @@ public override NBrightInfo AfterProductSave(NBrightInfo nbrightInfo)
var promoid = nbrightInfo.GetXmlPropertyInt("genxml/hidden/promoid"); // legacy promo flag
if (nbrightInfo.GetXmlPropertyBool("genxml/hidden/promoflag") || promoid > 0)
{
var prdData = ProductUtils.GetProductData(nbrightInfo.ItemID, nbrightInfo.Lang);
var prdData = ProductUtils.GetProductData(nbrightInfo.ItemID, nbrightInfo.PortalId, nbrightInfo.Lang);
// loop on models to get all promoid at model level.
var modelpromoids = new List<int>();
if (promoid > 0) modelpromoids.Add(promoid);
Expand Down Expand Up @@ -183,7 +171,7 @@ public override NBrightInfo AfterProductSave(NBrightInfo nbrightInfo)
var propapplygroupid = promoData.GetXmlPropertyInt("genxml/dropdownlist/propapply");

var removepromo = true;
foreach (var c in prdData.GetCategories())
foreach (var c in prdData.GetCategories(nbrightInfo.PortalId))
{
if (c.categoryid == catgroupid) removepromo = false;
if (c.categoryid == propgroupid) removepromo = false;
Expand Down
Loading

0 comments on commit 60da642

Please sign in to comment.