Пример #1
0
        protected virtual void InitializeTheme()
        {
            string theme = string.Empty;
            //GET DEFAULT STORE THEME
            Store store = Token.Instance.Store;

            if (store != null)
            {
                theme = store.Settings.StoreTheme;
                if (!string.IsNullOrEmpty(theme) && !CommerceBuilder.UI.Styles.Theme.Exists(theme))
                {
                    //INVALID THEME SELECTED
                    theme = string.Empty;
                }
            }
            //GET PAGE PATH
            SharedPersonalization personalization = SharedPersonalizationDataSource.LoadForPath(Request.AppRelativeCurrentExecutionFilePath, false);

            if (personalization != null)
            {
                if ((personalization.Theme != string.Empty) && (CommerceBuilder.UI.Styles.Theme.Exists(personalization.Theme)))
                {
                    theme = personalization.Theme;
                }
                if (personalization.MasterPageFile != string.Empty)
                {
                    this.MasterPageFile = personalization.MasterPageFile;
                }
            }
            //SET THE THEME
            if (!string.IsNullOrEmpty(theme))
            {
                this.Theme = theme;
            }
        }
Пример #2
0
        private static string GetThemeFromPersonalization(SharedPersonalization sp)
        {
            string theme = string.Empty;

            //GET THE DEFAULT STORE THEME FIRST
            Store store = CommerceBuilder.Common.Token.Instance.Store;

            if (store != null)
            {
                theme = store.Settings.StoreTheme;
                if (!string.IsNullOrEmpty(theme) && !CommerceBuilder.UI.Styles.Theme.Exists(theme))
                {
                    //INVALID THEME SELECTED
                    theme = string.Empty;
                }
            }

            //TRY TO GET THE THEME FROM PERSONALIZATION
            if (sp != null)
            {
                if ((sp.Theme != string.Empty) && (CommerceBuilder.UI.Styles.Theme.Exists(sp.Theme)))
                {
                    theme = sp.Theme;
                }
            }
            return(theme);
        }
Пример #3
0
        /// <summary>
        /// Parses shared personalization for the given virtual path to obtain the applied content scriptlet
        /// </summary>
        /// <param name="virtualPath">The virtual path to check for personalization data</param>
        /// <returns>The name of the content scriptlet applied in personalization data, or string.Empty
        /// if the value could not be determined</returns>
        private static string GetContentScriptletFromPersonalization(SharedPersonalization sp, string themeName)
        {
            // LOOK FOR SHARED PERSONALIZATION SET ON THE GIVEN VIRTUAL PATH
            if (sp != null)
            {
                // DECODE THE PERSONALIZATION BLOB
                Dictionary <string, PersonalizationInfo> props = sp.DecodePageSettings();

                // LOOP THE KEYS FOR THE PERSONALIZED PROPERTIES
                foreach (string key in props.Keys)
                {
                    // SEE IF THIS PERSONALIZATION DATA APPLIES TO SCRIPTLETPART
                    PersonalizationInfo pinfo = props[key];
                    if (pinfo.ControlType.Name == "ScriptletPart")
                    {
                        // SEE IF THERE IS A VALUE SET FOR THE CONTENT SCRIPTLET
                        if (pinfo.Properties.ContainsKey("Content"))
                        {
                            // TRY TO LOAD THE SPECIFIED CONTENT SCRIPTLET
                            string contentScriptlet = pinfo.Properties["Content"].ToString();
                            //Scriptlet s = ScriptletDataSource.Load(contentScriptlet, ScriptletType.Content);
                            Scriptlet s = ScriptletDataSource.Load(themeName, contentScriptlet, ScriptletType.Content);
                            if (s != null)
                            {
                                return(s.Identifier);
                            }
                        }
                    }
                }
            }

            // EITHER SHARED PERSONALIZATION WAS NOT SET, CONTENT SCRIPTLET SETTING IS UNAVAILABLE,
            // OR THE SPECIFIED CONTENT SCRIPTLET IS INVALID
            return(string.Empty);
        }
Пример #4
0
        /// <summary>
        /// Determines whether the configured web application is using one page checkout.
        /// </summary>
        /// <returns>True if one page checkout can be identified, false otherwise.</returns>
        public static bool IsUsingOnePageCheckout()
        {
            // THIS METHOD CAN ONLY WORK IF WE HAVE A VALID HTTP CONTEXT
            HttpContext context = HttpContext.Current;

            if (context == null)
            {
                throw new CommerceBuilderException("This method can only be called within an HTTP context.");
            }

            // CHECK FOR CACHED SETTING
            if (context.Cache[onePageCheckoutIndicatorCacheKey] == null)
            {
                // DETERMINE THE PRESENT VALUE FOR THE ONE PAGE CHECKOUT INDICATOR
                bool indicator;

                // IF WE IDENTIFY A SCRIPTLET IN USE, TRACK IT SO WE CAN SET UP CACHE DEPENDENCIES
                string scriptletName = string.Empty;
                string themeName     = string.Empty;

                // SEE IF THE EXPECTED CHECKOUT SCRIPT FILE CAN BE FOUND
                string checkoutFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Checkout\\Default.aspx");
                if (File.Exists(checkoutFilePath))
                {
                    SharedPersonalization sp = SharedPersonalizationDataSource.LoadForPath("~/Checkout/Default.aspx", false);
                    themeName = GetThemeFromPersonalization(sp);

                    // GET THE CONTENT SCRIPTLET CURRENTLY IN USE
                    scriptletName = GetContentScriptletFromPersonalization(sp, themeName);
                    if (string.IsNullOrEmpty(scriptletName))
                    {
                        scriptletName = GetDefaultContentScriptlet(checkoutFilePath);
                    }

                    // WAS A CONTENT SCRIPTLET IDENTIFIED?
                    if (!string.IsNullOrEmpty(scriptletName))
                    {
                        // YES, CHECK THE CONFIGURED CONTENT SCRIPTLET FOR THE ONE PAGE CHECKOUT CONTROL
                        indicator = IsOnePageCheckoutSetInScriptlet(themeName, scriptletName);
                    }
                    else
                    {
                        // NO, SCRIPTLET NOT FOUND SO PRESUME ONE PAGE CHECKOUT IS NOT IN USE
                        indicator = false;
                    }
                }
                else
                {
                    // THE EXPECTED CHECKOUT SCRIPT IS NOT PRESENT, SO PRESUME ONE PAGE CHECKOUT IS NOT IN USE
                    indicator = false;
                }

                // BUILD A LIST OF FILE DEPENDENCIES FOR THE CACHE INDICATOR
                List <string> fileDependencies = new List <string>();

                // WE NEED TO KNOW IF THE EXPECTED CHECKOUT SCRIPT CHANGES
                fileDependencies.Add(checkoutFilePath);

                // IF A SCRIPTLET WAS IDENTIFIED, WE SHOULD MONITOR FOR CHANGES
                if (!string.IsNullOrEmpty(scriptletName))
                {
                    // OBTAIN BASE APPLICATION DIRECTORY
                    string baseDirectory = AppDomain.CurrentDomain.BaseDirectory;

                    // BOTH DEFAULT AND CUSTOM SCRIPTLET SHOULD BE MONITORED
                    if (ThemeHasScriptlets(themeName))
                    {
                        fileDependencies.Add(Path.Combine(baseDirectory, "App_Themes\\" + themeName + "\\Scriptlets\\Default\\Content\\" + scriptletName + ".htm"));
                        fileDependencies.Add(Path.Combine(baseDirectory, "App_Themes\\" + themeName + "\\Scriptlets\\Custom\\Content\\" + scriptletName + ".htm"));
                    }
                    else
                    {
                        fileDependencies.Add(Path.Combine(baseDirectory, "App_Data\\Scriptlets\\Default\\Content\\" + scriptletName + ".htm"));
                        fileDependencies.Add(Path.Combine(baseDirectory, "App_Data\\Scriptlets\\Custom\\Content\\" + scriptletName + ".htm"));
                    }
                }

                // CREATE THE CACHE DEPENDENCY WITH LIST OF FILE PATHS
                CacheDependency fileDependency = new CacheDependency(fileDependencies.ToArray());

                // CACHE THE INDICATOR
                lock (syncLock)
                {
                    context.Cache.Remove(onePageCheckoutIndicatorCacheKey);
                    context.Cache.Add(onePageCheckoutIndicatorCacheKey, indicator, fileDependency, Cache.NoAbsoluteExpiration, Cache.NoSlidingExpiration, CacheItemPriority.High, null);
                }
            }

            // RETURN THE CACHED INDICATOR
            return(AlwaysConvert.ToBool(context.Cache[onePageCheckoutIndicatorCacheKey], false));
        }