paul.g wrote:
newsItem is the NewsItem domain entity, I assumed that was what you referred to with "news item". Yes, v4.0, should be same API in v3.x though.
Where are you trying to get hold of the store name: in a controller, razor view? Could you explain little more what you are trying to achieve.
Ok what I want todo is to add OG metadata to news view, so on the NewsItem.cshtml I need to pull store name.
Got ya! That you can achieve by following steps (not tested):
1. Create a new string property
StoreName on
NewsItemModel (either on the existing model or create a new
partial NewsItemModel)
public partial class NewsItemModel
{
public string StoreName { get; set; }
}
2. Set the StoreName property in
PrepareNewsItemModel in the
NewsModelFactory
private readonly IStoreMappingService _storeMappingService;
public NewsModelFactory(
...
IStoreMappingService storeMappingService)
{
...
_storeMappingService = storeMappingService;
}
public virtual NewsItemModel PrepareNewsItemModel(NewsItemModel model, NewsItem newsItem, bool prepareComments)
{
...
var storeMapping = _storeMappingService.GetStoreMappings(newsItem).FirstOrDefault();
if (storeMapping != null)
{
model.StoreName = storeMapping.Store.Name;
}
...
}
3. Use the StoreName propery in NewsItem.cshtml
@Model.StoreName
Is that what you are looking for?