/// <summary> /// Loads product options. /// </summary> private void LoadProductOptions() { DataSet dsCategories = null; if (IsLiveSite) { // Get cache minutes int cacheMinutes = SettingsKeyInfoProvider.GetIntValue(SiteContext.CurrentSiteName + ".CMSCacheMinutes"); // Try to get data from cache using (var cs = new CachedSection <DataSet>(ref dsCategories, cacheMinutes, true, null, "skuoptioncategories", SKUID)) { if (cs.LoadData) { // Get all option categories for SKU dsCategories = OptionCategoryInfoProvider.GetProductOptionCategories(SKUID, false); // Save to the cache if (cs.Cached) { // Get dependencies var dependencies = new List <string> { "ecommerce.sku|byid|" + SKUID, "ecommerce.optioncategory|all" }; // Set dependencies cs.CacheDependency = CacheHelper.GetCacheDependency(dependencies); } cs.Data = dsCategories; } } } else { // Get all option categories for SKU dsCategories = OptionCategoryInfoProvider.GetProductOptionCategories(SKUID, false); } // Initialize product option selectors if (!DataHelper.DataSourceIsEmpty(dsCategories)) { mProductOptions = new Hashtable(); // Is only one option category available for variants? var variantCategories = Variants.Any() ? Variants.First().ProductAttributes.CategoryIDs.ToList() : null; mOneCategoryUsed = variantCategories != null && variantCategories.Count == 1; foreach (DataRow dr in dsCategories.Tables[0].Rows) { try { // Load control for selection product options ProductOptionSelector selector = (ProductOptionSelector)LoadUserControl("~/CMSModules/Ecommerce/Controls/ProductOptions/ProductOptionSelector.ascx"); // Add control to the collection var categoryID = ValidationHelper.GetInteger(dr["CategoryID"], 0); selector.ID = "opt" + categoryID; // Init selector selector.LocalShoppingCartObj = ShoppingCart; selector.IsLiveSite = IsLiveSite; selector.CssClassFade = CssClassFade; selector.CssClassNormal = CssClassNormal; selector.SKUID = SKUID; selector.OptionCategory = new OptionCategoryInfo(dr); // If one category is used, fix the one selector with options to use only options which are not in disabled variants if (mOneCategoryUsed && variantCategories.Contains(categoryID)) { var disabled = from variant in Variants where !variant.Variant.SKUEnabled from productAttributes in variant.ProductAttributes select productAttributes.SKUID; var disabledList = disabled.ToList(); selector.ProductOptionsInDisabledVariants = disabledList.Any() ? disabledList : null; } // Load all product options foreach (DictionaryEntry entry in selector.ProductOptions) { mProductOptions[entry.Key] = entry.Value; } var lc = selector.SelectionControl as ListControl; if (lc != null) { // Add Index change handler lc.AutoPostBack = true; } pnlSelectors.Controls.Add(selector); } catch { } } } }
/// <summary> /// Loads product options. /// </summary> private void LoadProductOptions() { DataSet dsCategories = null; if (this.IsLiveSite) { // Get cache minutes int cacheMinutes = SettingsKeyProvider.GetIntValue(CMSContext.CurrentSiteName + ".CMSCacheMinutes"); // Try to get data from cache using (CachedSection <DataSet> cs = new CachedSection <DataSet>(ref dsCategories, cacheMinutes, true, null, "skuproductoptions", this.SKUID)) { if (cs.LoadData) { // Get the data dsCategories = OptionCategoryInfoProvider.GetSKUOptionCategories(this.SKUID, true); // Save to the cache if (cs.Cached) { cs.CacheDependency = CacheHelper.GetCacheDependency("ecommerce.sku|byid|" + this.SKUID); cs.Data = dsCategories; } } } } else { // Get the data dsCategories = OptionCategoryInfoProvider.GetSKUOptionCategories(this.SKUID, true); } // Initialize product option selectors if (!DataHelper.DataSourceIsEmpty(dsCategories)) { this.mProductOptions = new Hashtable(); foreach (DataRow dr in dsCategories.Tables[0].Rows) { try { // Load control for selection product options ProductOptionSelector selector = (ProductOptionSelector)LoadControl("~/CMSModules/Ecommerce/Controls/ProductOptions/ProductOptionSelector.ascx"); selector.ID = "opt" + ValidationHelper.GetInteger(dr["CategoryID"], 0); selector.LocalShoppingCartObj = this.ShoppingCart; selector.ShowPriceIncludingTax = this.ShowPriceIncludingTax; // Set option category data to the selector selector.OptionCategory = new OptionCategoryInfo(dr); // Load all product options foreach (DictionaryEntry entry in selector.ProductOptions) { this.mProductOptions[entry.Key] = entry.Value; } if (this.ShowTotalPrice) { ListControl lc = selector.SelectionControl as ListControl; if (lc != null) { // Add Index change handler lc.AutoPostBack = true; lc.SelectedIndexChanged += new EventHandler(Selector_SelectedIndexChanged); } } // Add control to the collection this.pnlSelectors.Controls.Add(selector); } catch { } } } }
/// <summary> /// Loads product options. /// </summary> private void LoadProductOptions() { // Get all option categories for SKU DataSet dsCategories = OptionCategoryInfoProvider.GetProductOptionCategories(SKUID, false); // Initialize product option selectors if (!DataHelper.DataSourceIsEmpty(dsCategories)) { mProductOptions = new Hashtable(); // Is only one option category available for variants? var variantCategories = Variants.Any() ? Variants.First().ProductAttributes.CategoryIDs.ToList() : null; mOneCategoryUsed = variantCategories != null && variantCategories.Count == 1; foreach (DataRow dr in dsCategories.Tables[0].Rows) { try { // Load control for selection product options ProductOptionSelector selector = (ProductOptionSelector)LoadUserControl("~/CMSModules/Ecommerce/Controls/ProductOptions/ProductOptionSelector.ascx"); // Add control to the collection var categoryID = ValidationHelper.GetInteger(dr["CategoryID"], 0); selector.ID = "opt" + categoryID; // Init selector selector.LocalShoppingCartObj = ShoppingCart; selector.IsLiveSite = false; selector.CssClassFade = "text-muted"; selector.CssClassNormal = "normal"; selector.SKUID = SKUID; selector.OptionCategory = new OptionCategoryInfo(dr); // If one category is used, fix the one selector with options to use only options which are not in disabled variants if (mOneCategoryUsed && variantCategories.Contains(categoryID)) { var disabled = from variant in Variants where !variant.Variant.SKUEnabled from productAttributes in variant.ProductAttributes select productAttributes.SKUID; var disabledList = disabled.ToList(); selector.ProductOptionsInDisabledVariants = disabledList.Any() ? disabledList : null; } // Load all product options foreach (DictionaryEntry entry in selector.ProductOptions) { mProductOptions[entry.Key] = entry.Value; } var lc = selector.SelectionControl as ListControl; if (lc != null) { // Add Index change handler lc.AutoPostBack = true; } pnlSelectors.Controls.Add(selector); } catch { } } } }