Dynamically Change Theme via URL !

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
12 years ago
Hello Friends

Is it possible to change the theme of a nopCommerce shop via a URL ?

I'm sure some of you know of NC Themes (http://www.ncthemes.com). Basically it is a Theme shop selling nopCommerce 2.xx themes.

What I did originally was, that for each theme I had, I created a sub-domain for it, and installed the new theme on there, then link my customers to demo the theme on that sub-domain.

This is fine if you have 1 or 2 themes (= 1 or 2 sub-domains) .. but as time passes, I'll have more and more themes, and I don't think it is efficient to have more and more sub-domains << kills server resources ..etc (not to mention the pain of setting the site up ..etc) :(

So what I had in mind was, have 1 nopCommerce installation as a sub-domain, then dynamically change the theme of that 1 installation to the desired demo-ing theme required by the customer.

Is it possible ? I believe it will require some modding, but how hard do you think it is ?

I would greatly appreciate some help and advice.

Thank You.
12 years ago
add a themes field (collection) to product variants.
12 years ago
hmm how would that help dynamically change the theme when a user clicks the Demo button ?
12 years ago
if i understood u correct, a theme is a product on your store.
a client press  one of the themes (product), u redirect the client to the product page, get the themeId and change the theme according to the themeId.
then the client see the product, description, price and so... and feel the visual look of that theme.
12 years ago
nearly correct.

I don't want the theme of my shop changing. I want the theme of a separate nopCommerce installation changing. I hope it is clear now.

You can find my current solution here (http://www.ncthemes.com), but like I said it is not ideal, because for each new theme I have to create another site.

Thanks
12 years ago
do as follow:
install all themes on the demo store.
pass the name of the theme to the demo store
set the storeInformationSettings.DefaultStoreTheme = "the name of the theme"
do it after nop loads all settings
u should avoid using cach or always set themeIsCached to false

the only problem with this method that the store theme will be changed every time someone linked to it.
to avoid that u can store the theme name in a cookie (or a theme field on current customer) and load it from there instead of the settings table in db  
u need to override the WorkingTheme in the ThemeContext class

Nop commerce does not save theme in DB or file, it runs on all sub folders under "/themes/" and insert them into one object called "themeProvider" for every theme there is a theme.config, make sure the name that u pass is equal to the name in the theme.config
12 years ago
www.yourdomain.com?themename=darkorange
the above is the link that u should point to your store.

add the following

open namespace Nop.Web.Controllers.BaseNopController.cs

method:  protected override void OnActionExecuting(ActionExecutingContext filterContext)
add:
CheckThemes();

and add:

protected virtual void CheckThemes()
        {
            if (Request != null &&
                Request.QueryString != null && Request.QueryString["ThemeName"] != null)
            {
                var ThemeName = Request.QueryString["ThemeName"].ToString();

                if (ThemeName != null && ThemeName != "")
                {
                    EngineContext.Current.Resolve<StoreInformationSettings>().DefaultStoreTheme = ThemeName;
                }
            }
        }
12 years ago
Hezyz it worked beautifully. Thank you ever so much. :)
12 years ago
i forgot to save the settings.
if u link to another page it will go back to the saved theme.
u have to save the settings at the end of the method
12 years ago
Oh, how do I do that ? is it .save() ?
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.