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

Posted: November 07, 2017 at 10:00 AM Quote #195776
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
This post/answer is useful
0
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Posted: November 07, 2017 at 12:42 PM Quote #195784
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>
This post/answer is useful
0
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Posted: November 14, 2017 at 8:13 AM Quote #196162
sina, thanks for your response.  I'll give it a try!
This post/answer is useful
0
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Posted: November 14, 2017 at 8:25 AM Quote #196163
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?
This post/answer is useful
0
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Posted: November 14, 2017 at 8:28 AM Quote #196165
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!
This post/answer is useful
0
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Posted: November 16, 2017 at 1:48 AM Quote #196277
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 post/answer is useful
0
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Premium support services
  • Dedicated premium support services provided by core developers are intended for persons who run mission critical websites, work on projects with tight deadlines, or want to get dedicated support.
Professional services
  • Want to open a new store? Want to take your store to the next level? Need a custom extension? We can customize nopCommerce to fit your store perfectly. Request a quote to get started.