Skip to content

Commit 60da642

Browse files
authored
Merge pull request #189 from DNNMonster/bugfix/portal-id-usage
Enhance portal id usage
2 parents 9ed4af1 + 746c6ea commit 60da642

File tree

6 files changed

+83
-59
lines changed

6 files changed

+83
-59
lines changed

Components/GrpCatController.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,10 +338,15 @@ public List<GroupCategoryData> GetProductCategories(int productid, String groupr
338338
notcat = "cat";
339339
}
340340

341-
var joinItems = (from d1 in GrpCategoryList
341+
var joinItems = new List<GroupCategoryData>();
342+
if (GrpCategoryList != null)
343+
{
344+
joinItems = (from d1 in GrpCategoryList
342345
join d2 in catxrefList on d1.categoryid equals d2.XrefItemId
343346
where (d1.grouptyperef == groupref || groupref == "") && d1.grouptyperef != notcat
344347
select d1).OrderBy(d1 => d1.grouptyperef).ThenBy(d1 => d1.breadcrumb).ToList<GroupCategoryData>();
348+
349+
}
345350
return joinItems;
346351
}
347352

Components/NBrightBuyController.cs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -915,28 +915,33 @@ private static NBrightInfo UpdateLangNodeFields(String xmlname, NBrightInfo base
915915
return dlang;
916916
}
917917

918-
/// <summary>
919-
/// Get current portal StoreSettings
920-
/// </summary>
921-
/// <returns></returns>
922-
public static StoreSettings GetCurrentPortalData()
923-
{
918+
public static StoreSettings GetPortalData(int portalId)
919+
{
924920
StoreSettings objPortalSettings = null;
925921
if (HttpContext.Current != null)
926922
{
927923
// build StoreSettings and place in httpcontext
928-
if (HttpContext.Current.Items["NBBStoreSettings" + PortalSettings.Current.PortalId.ToString("")] == null)
924+
if (HttpContext.Current.Items["NBBStoreSettings" + portalId.ToString()] == null)
929925
{
930-
HttpContext.Current.Items.Add("NBBStoreSettings" + PortalSettings.Current.PortalId.ToString(""),GetStaticStoreSettings(PortalSettings.Current.PortalId));
926+
HttpContext.Current.Items.Add("NBBStoreSettings" + portalId.ToString(), GetStaticStoreSettings(portalId));
931927
}
932-
objPortalSettings = (StoreSettings)HttpContext.Current.Items["NBBStoreSettings" + PortalSettings.Current.PortalId.ToString("")];
928+
objPortalSettings = (StoreSettings)HttpContext.Current.Items["NBBStoreSettings" + portalId.ToString()];
933929
}
934930
else
935931
{
936932
// capture all to ensure we pass something.
937-
objPortalSettings = GetStaticStoreSettings(PortalSettings.Current.PortalId);
933+
objPortalSettings = GetStaticStoreSettings(portalId);
938934
}
939935
return objPortalSettings;
936+
}
937+
938+
/// <summary>
939+
/// Get current portal StoreSettings
940+
/// </summary>
941+
/// <returns></returns>
942+
public static StoreSettings GetCurrentPortalData()
943+
{
944+
return GetPortalData(PortalSettings.Current.PortalId);
940945
}
941946

942947
/// <summary>

Components/Product/ProductData.cs

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -444,14 +444,15 @@ public NBrightInfo GetOptionValue(String optionid, String optionvalueid)
444444
/// <summary>
445445
/// Select categories linked to product, by groupref
446446
/// </summary>
447+
/// <param name="portalId"></param>
447448
/// <param name="groupref">groupref for select, "" = all, "cat"= Category only, "!cat" = all non-category, "{groupref}"=this group only</param>
448449
/// <param name="cascade">get all cascade records to get all parent categories</param>
449450
/// <returns></returns>
450-
public List<GroupCategoryData> GetCategories(String groupref = "", Boolean cascade = false)
451+
public List<GroupCategoryData> GetCategories(int portalId, String groupref = "", Boolean cascade = false)
451452
{
452453
if (Info == null) return new List<GroupCategoryData>(); // stop throwing an error no product exists,
453454

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

472+
473+
/// <summary>
474+
/// Select categories linked to product, by groupref
475+
/// </summary>
476+
/// <param name="groupref">groupref for select, "" = all, "cat"= Category only, "!cat" = all non-category, "{groupref}"=this group only</param>
477+
/// <param name="cascade">get all cascade records to get all parent categories</param>
478+
/// <returns></returns>
479+
public List<GroupCategoryData> GetCategories(String groupref = "", Boolean cascade = false)
480+
{
481+
var portalId = PortalSettings.Current.PortalId;
482+
return GetCategories(portalId, groupref, cascade);
483+
}
484+
471485
/// <summary>
472486
/// Select properties linked to product, by groupref
473487
/// </summary>
@@ -689,6 +703,7 @@ public void Save(bool triggerevent, bool newrecord)
689703
DataRecord = objCtrl.Get(productid);
690704
DataLangRecord = objCtrl.Get(plangid);
691705
}
706+
692707
}
693708

694709
private void UpdateDisplayCalcPrices()
@@ -1744,6 +1759,7 @@ public int Validate()
17441759
}
17451760
lp += 1;
17461761
}
1762+
17471763
//Fix document paths
17481764
lp = 1;
17491765
foreach (var d in Docs)
@@ -1794,7 +1810,7 @@ public int Validate()
17941810
}
17951811

17961812
// remove duplicate category xrefs.
1797-
var catlist = GetCategories();
1813+
var catlist = GetCategories(_portalId);
17981814
foreach (var c in catlist)
17991815
{
18001816
var l = objCtrl.GetList(_portalId, -1, "CATXREF", " and NB1.ParentItemId = " + Info.ItemID.ToString("") + " and NB1.XrefItemId = " + c.categoryid.ToString(""));
@@ -1835,6 +1851,7 @@ public int Validate()
18351851
objCtrl.Delete(c.ItemID);
18361852
errorcount += 1;
18371853
}
1854+
18381855
// remove catcascade record that have no catxref record for the product.
18391856
var caslist = new List<int>();
18401857
var catcascadelist = objCtrl.GetList(_portalId, -1, "CATCASCADE", " and nb1.ParentItemId = '" + Info.ItemID + "' ");
@@ -1843,10 +1860,10 @@ public int Validate()
18431860
caslist.Add(n.XrefItemId);
18441861
}
18451862

1846-
var catlist2 = GetCategories();
1863+
var catlist2 = GetCategories(_portalId);
18471864
if (catlist2.Any())
18481865
{
1849-
var objGrpCtrl = new GrpCatController(_lang, true);
1866+
var objGrpCtrl = new GrpCatController(_lang, _portalId, true);
18501867
foreach (var cat in catlist2)
18511868
{
18521869
var parentcats = objGrpCtrl.GetCategory(cat.categoryid);
@@ -1876,10 +1893,9 @@ public int Validate()
18761893
}
18771894
}
18781895

1879-
1880-
18811896
// update shared product if flagged
1882-
if (StoreSettings.Current.GetBool("shareproducts") && DataRecord.PortalId >= 0)
1897+
StoreSettings storeSettings = (System.Web.HttpContext.Current != null) ? StoreSettings.Current : new StoreSettings(_portalId);
1898+
if (storeSettings.GetBool("shareproducts") && DataRecord.PortalId >= 0)
18831899
{
18841900
upd = true;
18851901
DataRecord.PortalId = -1;
@@ -1889,7 +1905,7 @@ public int Validate()
18891905
}
18901906
}
18911907

1892-
// check if we have empty model name ()
1908+
// check if we have empty model name
18931909
var modellp = 1;
18941910
foreach (var m in Models)
18951911
{
@@ -1975,13 +1991,11 @@ public int Validate()
19751991
}
19761992
}
19771993

1978-
19791994
return errorcount;
19801995
}
19811996

19821997
public int Copy()
19831998
{
1984-
19851999
var objCtrl = new NBrightBuyController();
19862000

19872001
//Copy Base record
@@ -2083,7 +2097,6 @@ public void FillEmptyLanguageFields()
20832097
}
20842098
}
20852099

2086-
20872100
// models
20882101
var nodList1 = DataLangRecord.XMLDoc.SelectNodes("genxml/models/genxml");
20892102
if (nodList1 != null)
@@ -2214,15 +2227,11 @@ public void FillEmptyLanguageFields()
22142227
}
22152228
}
22162229

2217-
22182230
public void OutputDebugFile(String filePathName)
22192231
{
22202232
Info.XMLDoc.Save(filePathName);
22212233
}
22222234

2223-
2224-
2225-
22262235
#endregion
22272236

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

23122321
private int AddNew()
23132322
{
2314-
23152323
var nbi = new NBrightInfo(true);
23162324
if (StoreSettings.Current.Get("shareproducts") == "True") // option in storesetting to share products created here across all portals.
23172325
_portalId = -1;
@@ -2468,7 +2476,6 @@ public Double GetDealerSalePriceDouble()
24682476
return price;
24692477
}
24702478

2471-
24722479
private bool CheckClientFileUpload()
24732480
{
24742481
return Info.GetXmlPropertyBool("genxml/checkbox/chkfileupload");

Components/Product/ProductUtils.cs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -455,29 +455,48 @@ private static List<string> BuildModelCodes(List<NBrightInfo> optList, int lpPos
455455
return mcList;
456456
}
457457

458-
459458
/// <summary>
460459
/// Get ProductData class with cacheing
461460
/// </summary>
462461
/// <param name="productId"></param>
462+
/// <param name="portalId"></param>
463463
/// <param name="lang"></param>
464464
/// <param name="hydrateLists"></param>
465465
/// <param name="typeCode">Typecode of record default "PRD"</param>
466466
/// <param name="typeLangCode">Langauge Typecode of record default "PRDLANG"</param>
467467
/// <returns></returns>
468-
public static ProductData GetProductData(int productId, String lang, Boolean hydrateLists = true, String typeCode = "PRD")
468+
public static ProductData GetProductData(int productId, int portalId, String lang, Boolean hydrateLists = true, String typeCode = "PRD")
469469
{
470470
ProductData prdData;
471471
var cacheKey = "NBSProductData*" + productId.ToString("") + "*" + lang;
472472
prdData = (ProductData)Utils.GetCache(cacheKey);
473473
if ((prdData == null) || (productId == -1))
474474
{
475-
prdData = new ProductData(productId, lang, hydrateLists, typeCode);
475+
prdData = new ProductData(productId, portalId, lang, hydrateLists, typeCode);
476476
Utils.SetCache(cacheKey, prdData);
477477
}
478478
return prdData;
479479
}
480480

481+
482+
/// <summary>
483+
/// Get ProductData class with cacheing
484+
/// </summary>
485+
/// <param name="productId"></param>
486+
/// <param name="lang"></param>
487+
/// <param name="hydrateLists"></param>
488+
/// <param name="typeCode">Typecode of record default "PRD"</param>
489+
/// <param name="typeLangCode">Langauge Typecode of record default "PRDLANG"</param>
490+
/// <returns></returns>
491+
public static ProductData GetProductData(int productId, String lang, Boolean hydrateLists = true, String typeCode = "PRD")
492+
{
493+
if (Utils.IsNumeric(productId))
494+
{
495+
return GetProductData(Convert.ToInt32(productId), PortalSettings.Current.PortalId, lang, hydrateLists, typeCode);
496+
}
497+
return null;
498+
}
499+
481500
public static ProductData GetProductData(String productId, String lang, Boolean hydrateLists = true)
482501
{
483502
if (Utils.IsNumeric(productId))

Providers/PromoProvider/PromoProvider.cs

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,8 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Globalization;
4-
using System.Linq;
5-
using System.Text;
6-
using System.Web.Hosting;
7-
using System.Web.UI.WebControls;
8-
using System.Xml;
9-
using DotNetNuke.Common.Utilities;
10-
using DotNetNuke.Entities.Portals;
11-
using NBrightCore.common;
1+
using NBrightCore.common;
122
using NBrightDNN;
133
using Nevoweb.DNN.NBrightBuy.Components;
4+
using System;
5+
using System.Collections.Generic;
146

157
namespace Nevoweb.DNN.NBrightBuy.Providers.PromoProvider
168
{
@@ -20,17 +12,14 @@ public override string DoWork(int portalId)
2012
{
2113
return PromoUtils.CalcGroupPromo(portalId);
2214
}
23-
2415
}
2516

26-
2717
public class MultiBuyPromoScheudler : Components.Interfaces.SchedulerInterface
2818
{
2919
public override string DoWork(int portalId)
3020
{
3121
return PromoUtils.CalcMultiBuyPromo(portalId);
3222
}
33-
3423
}
3524

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

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

72-
73-
// Applied discount to this single cart item
61+
// Applied discount to this single cart item
7462
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
7563
{
7664
var dteF = Convert.ToDateTime(validfrom).Date;
@@ -155,7 +143,7 @@ public override NBrightInfo AfterProductSave(NBrightInfo nbrightInfo)
155143
var promoid = nbrightInfo.GetXmlPropertyInt("genxml/hidden/promoid"); // legacy promo flag
156144
if (nbrightInfo.GetXmlPropertyBool("genxml/hidden/promoflag") || promoid > 0)
157145
{
158-
var prdData = ProductUtils.GetProductData(nbrightInfo.ItemID, nbrightInfo.Lang);
146+
var prdData = ProductUtils.GetProductData(nbrightInfo.ItemID, nbrightInfo.PortalId, nbrightInfo.Lang);
159147
// loop on models to get all promoid at model level.
160148
var modelpromoids = new List<int>();
161149
if (promoid > 0) modelpromoids.Add(promoid);
@@ -183,7 +171,7 @@ public override NBrightInfo AfterProductSave(NBrightInfo nbrightInfo)
183171
var propapplygroupid = promoData.GetXmlPropertyInt("genxml/dropdownlist/propapply");
184172

185173
var removepromo = true;
186-
foreach (var c in prdData.GetCategories())
174+
foreach (var c in prdData.GetCategories(nbrightInfo.PortalId))
187175
{
188176
if (c.categoryid == catgroupid) removepromo = false;
189177
if (c.categoryid == propgroupid) removepromo = false;

0 commit comments

Comments
 (0)