Add Address and Phone Number to top Header for multi-tenant site

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
6 years ago
I have an instance with multiple different stores some of which have different locations. I have setup each location as a store and these stores share a catalog, but have different subdomains that direct the user to the proper store.  I have a request to add the address and phone number to the top header for some stores (which those that do not want it on their site I intend to leave blank in the store configuration).  Everything I am finding involves hard coding the address and phone in the html.  How can I use the variables from the store configuration to display this information for each individual store rather than having to hard code it.  Primarily I need the variable names, where to set them if they are not already set, and where to place the changes in the HTML.

Any assistance or direction anyone can provide would be greatly appreciated.

Thanks,
Jeff
6 years ago
jcrumble wrote:
I have an instance with multiple different stores some of which have different locations. I have setup each location as a store and these stores share a catalog, but have different subdomains that direct the user to the proper store.  I have a request to add the address and phone number to the top header for some stores (which those that do not want it on their site I intend to leave blank in the store configuration).  Everything I am finding involves hard coding the address and phone in the html.  How can I use the variables from the store configuration to display this information for each individual store rather than having to hard code it.  Primarily I need the variable names, where to set them if they are not already set, and where to place the changes in the HTML.

Any assistance or direction anyone can provide would be greatly appreciated.

Thanks,
Jeff


You can take the benefit of setting service of nopcommerce. Go to http://yourstore/Admin/Setting/AllSettings and data accordingly and retrieve them by the name and storeid like


store1.address              yourstore1addressvalue    store1.
store2.address              yourstore2addressvalue    store2.


Then at view(.cshtml) can retrieve the address like bellow


    var CurrentStore = EngineContext.Current.Resolve<IStoreContext>().CurrentStore;
    var _settingService = EngineContext.Current.Resolve<ISettingService>();
    var CurrentStoreAddress = _settingService.GetSetting("store1.address", CurrentStore.Id);


You need to add the namespace of the EngineContext,IStoreContext and ISettingService  at top of the view like bellow

@using Nop.Core.Infrastructure
@using Nop.Core
@using Nop.Services.Configuration



So the full code should be like bellow to retrieve address of the specific store.


@using Nop.Core.Infrastructure
@using Nop.Core
@using Nop.Services.Configuration

@{
    var CurrentStore = EngineContext.Current.Resolve<IStoreContext>().CurrentStore;
    var _settingService = EngineContext.Current.Resolve<ISettingService>();
    var CurrentStoreAddress = _settingService.GetSetting("store1.address", CurrentStore.Id);
}




<div>@CurrentStoreAddress.Value</div>
6 years ago
sina, thanks for your response.  I'll give it a try!
6 years ago
The issue I ran into is that the view.cshtml is shared across stores.  The parameter would need to be dynamically assigned according to the store for a multi-tenant site.  If I specify a specific parameter then it shows the address on each and every store.  This is a version of NopCommerce on WinHost so the only access I have to the code is the cshtml not the APIs that are compiled.  Any other ideas or suggestions?
6 years ago
The address is already located under configuration > stores > StoreName.  If anyone knows how to access that in the cshtml as a parameter based on store then the above example should work to fit my needs by changing out the parameter.  Any assistance would be appreciated.

Thanks!
6 years ago
jcrumble wrote:
The address is already located under configuration > stores > StoreName.  If anyone knows how to access that in the cshtml as a parameter based on store then the above example should work to fit my needs by changing out the parameter.  Any assistance would be appreciated.

Thanks!



You can get current store name by the bellow code


@using Nop.Core.Infrastructure
@using Nop.Core
@using Nop.Services.Configuration

@{
    var CurrentStore = EngineContext.Current.Resolve<IStoreContext>().CurrentStore;
    var CurrentStoreName = CurrentStore.Name;
}
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.