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> publicpartialclass WebStoreContext : BasePlugin, IStoreContext { privatereadonly IStoreService _storeService; privatereadonly IWebHelper _webHelper;
/// <summary> /// Gets or sets the current store /// </summary> publicvirtual 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) thrownew Exception("No store could be loaded");
/// <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);
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");
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