Multi Stores with sub domains

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
8 years ago
Glad to know its fixed.
8 years ago
[email protected] wrote:
my solution for Multistore without subdomains and multiple wildcard sslzertificats.

each currency can have its own store . so fixed shippingprice per currencny are possible.

just recomple the Nop.Web.Framework  and set the store by Querystring Param setstore=storehost

example:
mystore.com?setstore=store1
mystore.com?setstore=store2

storesettings hostvalues must contains 'store1' or store2


Hi Giordano,
I followed your instructions
For testing purpose i have created sub-domain and created store as given below


Below is the code of WebStoreContex.Cs

using System;
using System.Linq;
using Nop.Core;
using Nop.Core.Domain.Stores;
using Nop.Services.Stores;
using Nop.Core.Infrastructure;
using System.Web;
using Nop.Core.Plugins;
using Nop.Services.Configuration;
namespace Nop.Web.Framework
{
    /// <summary>
    /// Store context for web application
    /// </summary>
    public partial class WebStoreContext : BasePlugin, IStoreContext
    {
        private readonly IStoreService _storeService;
        private readonly IWebHelper _webHelper;

        private readonly ISettingService _settingService;
        private Store _cachedStore;
        public WebStoreContext(IStoreService storeService, IWebHelper webHelper, ISettingService settingService)
        {
            this._storeService = storeService;
            this._webHelper = webHelper;
            this._settingService = settingService;
        }

        /// <summary>
        /// Gets or sets the current store
        /// </summary>
        public virtual Store CurrentStore
        {
            get
            {
                if (_cachedStore != null)
                    return _cachedStore;

                //ty to determine the current store by HTTP_HOST

                var host = _webHelper.ServerVariables("HTTP_HOST");
                //giordano storeselectore
                var settstring = string.Empty;
                var cookiestring = _webHelper.ServerVariables("HTTP_COOKIE").ToString().Split(new Char[] { ';' });
                foreach (var cookieitem in cookiestring)
                {
                    if (cookieitem.Contains("customer"))
                    {
                        settstring = cookieitem;
                    }
                }


                if (!String.IsNullOrEmpty(_webHelper.QueryString<string>("city").ToString()) && !string.IsNullOrEmpty(settstring))
                {
                    string city = _webHelper.QueryString<string>("city").ToString();
                    var setting = new Nop.Core.Domain.Configuration.Setting();
                    setting.Name = "giordano.store-" + settstring;
                    setting.Value = city;
                    _settingService.SetSetting(setting.Name, setting.Value);

                }

                var customerstore = _settingService.GetSettingByKey<string>("giordano.store-" + settstring);
                if (!String.IsNullOrEmpty(customerstore))
                {
                    host = customerstore;
                }


                //orginal

                var allStores = _storeService.GetAllStores();
                var store = allStores.FirstOrDefault(s => s.ContainsHostValue(host));

                if (store == null)
                {
                    //load the first found store
                    store = allStores.FirstOrDefault();
                }
                if (store == null)
                    throw new Exception("No store could be loaded");

                _cachedStore = store;
                return _cachedStore;
            }
        }
    }
}


Please help me. I need this this feature extremely. I need to create store as city and let the user select those city.
8 years ago
hello kalpeshbhadra

sorry our late response.

did you try to chage your stores now via


mystore.com?city=abc
mystore.com?city=xyz


just compile folling code in your Nop.Web.Framework.dll

or download it here http://www.giordano.ch/Portals/0/media/Produkte/NOPCommerce/Nop.Web.Framework.dll.zip

and use
www.Domain.com?setstore=abc
www.Domain.com?setstore=xyz


regards
André
giordano.ch


using System;
using System.Linq;
using Nop.Core;
using Nop.Core.Domain.Stores;
using Nop.Services.Stores;
using Nop.Core.Infrastructure;

using System.Web;
using Nop.Core.Plugins;
using Nop.Services.Configuration;


namespace Nop.Web.Framework
{
    /// <summary>
    /// Store context for web application
    /// </summary>
    public partial class WebStoreContext : BasePlugin, IStoreContext
    {
        private readonly IStoreService _storeService;
        private readonly IWebHelper _webHelper;

        private readonly ISettingService _settingService;


        private Store _cachedStore;

        public WebStoreContext(IStoreService storeService, IWebHelper webHelper, ISettingService settingService)
        {
            this._storeService = storeService;
            this._webHelper = webHelper;
            this._settingService = settingService;


        }

        /// <summary>
        /// Gets or sets the current store
        /// </summary>
        public virtual Store CurrentStore
        {
            get
            {
                if (_cachedStore != null)
                    return _cachedStore;

                //ty to determine the current store by HTTP_HOST

                var host = _webHelper.ServerVariables("HTTP_HOST");



                //giordano storeselectore
                var settstring = string.Empty;
                var cookiestring = _webHelper.ServerVariables("HTTP_COOKIE").ToString().Split(new Char[] { ';' });
                foreach (var cookieitem in cookiestring)
                {
                    if (cookieitem.Contains("customer"))
                    {
                        settstring = cookieitem;
                    }
                }

                try
                {
                    if (!String.IsNullOrEmpty(_webHelper.QueryString<string>("setstore").ToString()) && !string.IsNullOrEmpty(settstring))
                    {
                        string setstore = _webHelper.QueryString<string>("setstore").ToString();
                        var setting = new Nop.Core.Domain.Configuration.Setting();
                        setting.Name = "giordano.store-" + settstring;
                        setting.Value = setstore;
                        _settingService.SetSetting(setting.Name, setting.Value);

                    }
                }
                catch (Exception ex)
                {
                    //File.AppendAllText(HostingEnvironment.ApplicationPhysicalPath + "/App_Data/err.txt", "errr: " + ex.Message + host);
                }

                var customerstore = _settingService.GetSettingByKey<string>("giordano.store-" + settstring);
                if (!String.IsNullOrEmpty(customerstore))
                {
                    host = customerstore;
                }


                //orginal


                var allStores = _storeService.GetAllStores();
                var store = allStores.FirstOrDefault(s => s.ContainsHostValue(host));

                if (store == null)
                {
                    //load the first found store
                    store = allStores.FirstOrDefault();
                }
                if (store == null)
                    throw new Exception("No store could be loaded");

                _cachedStore = store;
                return _cachedStore;
            }
        }
    }
}
8 years ago
Thank you so much Giordano. It works fine with nopCommerce 3.6.
7 years ago
Hi Giordano,

I downloaded the DLL from the link you provided and replace the original DLL with your in my NopCommerce server and refresh the site.

I got an error message below.

The requested service 'Nop.Core.Data.DataSettings' has not been registered.

Once I restored the original DLL back, my site work properly then.

Is there anything I need to set and make your solution works?

Appreciate your help.

Sanguan
7 years ago
hello Sanguan

the download works for nop 3.6
which version do you currently use?

regards
andré
7 years ago
I'm using the latest version, 3.7 I think.

Is there anyway to make it works on the 3.7 please?
7 years ago
for NOP 3.7  - with the same concept
just place the dll in the bin folder
http://www.giordano.ch/Portals/0/media/Produkte/NOPCommerce/Nop.Web.Framework.dll3.7.zip
7 years ago
Thanks! It's works on 3.7 :)

Really appreciate

Sanguan
7 years ago
this link works

Please have a look at the following article - Setting Up Multi-stores. I presume you're interested in steps 1-3[/quote]
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.