Just wanted to share my solution for version 3.40. I am only really concerned about the product page breadcrumbs linking back to whatever category the user came from and passing the querystring value that is used for paging, but only if necessary. Thanks jhollan3 for helping me get started with this.
Nop.Web\Controllers\ProductController.cs
========================================
Replaced the #region Breadcrumb with the following. Needed to disable caching...
#region Breadcrumb
//do not prepare this model for the associated products. any it's not used
if (_catalogSettings.CategoryBreadcrumbEnabled && !isAssociatedProduct)
{
var breadcrumbModel = new ProductDetailsModel.ProductBreadcrumbModel()
{
Enabled = _catalogSettings.CategoryBreadcrumbEnabled,
ProductId = product.Id,
ProductName = product.GetLocalized(x => x.Name),
ProductSeName = product.GetSeName()
};
var productCategories = _categoryService.GetProductCategoriesByProductId(product.Id);
if (productCategories.Count > 0)
{
var category = productCategories[0].Category;
if (Request.ServerVariables["HTTP_REFERER"] != null) {category = GetReferringCategory(Request.UrlReferrer.AbsolutePath, productCategories);}
if (category != null)
{
foreach (var catBr in category.GetCategoryBreadCrumb(_categoryService, _aclService, _storeMappingService))
{
breadcrumbModel.CategoryBreadcrumb.Add(new CategorySimpleModel()
{
Id = catBr.Id,
Name = catBr.GetLocalized(x => x.Name),
SeName = catBr.GetSeName()
});
}
}
}
model.Breadcrumb = breadcrumbModel;
}
#endregion
... Added this function to the same class file. Note this uses URLRecord table instead of parsing for URL for "c"...
#region Custom
private Category GetReferringCategory(string referringUrl, IList<ProductCategory> categories)
{
string[] referringUrlSplit = referringUrl.Split('/');
if (referringUrlSplit.Length > 0)
{
for (int i = 0; i < referringUrlSplit.Length; i++)
{
if (referringUrlSplit[i].Length > 0)
{
var referringCategoryURL = referringUrlSplit[i];
var urlRecordService = Nop.Core.Infrastructure.EngineContext.Current.Resolve<IUrlRecordService>();
UrlRecord url = urlRecordService.GetBySlug(referringCategoryURL);
if (url != null)
{
if (url.EntityName.ToLower() == "category")
{
var referringCategory = (from c in categories where c.CategoryId == url.EntityId select c).ToList().First();
return referringCategory.Category;
}
}
}
}
}
return categories[0].Category;
}
#endregion
... Then modified the product breadcrumb view to attach referring querystring to url only when necessary.. following is the relevent code to replace on that file...
Nop.Web\Views\Product\_ProductBreadcrumb.cshtml
===============================================
@foreach (var category in Model.CategoryBreadcrumb)
{
var modUrl = Url.RouteUrl("Category", new { SeName = category.SeName });
if (Model.CategoryBreadcrumb.IndexOf(category) == Model.CategoryBreadcrumb.Count - 1)
{
if (Request.ServerVariables["HTTP_REFERER"] != null && Request.ServerVariables["HTTP_REFERER"].Contains("?"))
{
var querystring = Request.ServerVariables["HTTP_REFERER"].Substring(Request.ServerVariables["HTTP_REFERER"].IndexOf('?') + 1);
modUrl += "?" + querystring;
}
}
<li>
<span itemscope itemtype="http://data-vocabulary.org/Breadcrumb">
<a href="@modUrl" itemprop="url">
<span itemprop="title">@category.Name</span>
</a>
</span>
<span class="delimiter">@breadcrumbDelimiter</span>
</li>
}
... that's it... Hope someone finds this userful :)