-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Closed
Description
I came up with this solution for now by editing the SearchController, and it seems to work. I do think this should be a formal setting in the catalog/search settings. I added GetExactMatchFromSkuOrMpn to the IProductService but the name is self-explanatory. The other thing that this should do is if the SKU or MPN matches to a attribute combination of the product, it should go to that product page with the variant url.
public ActionResult Search(CatalogSearchQuery query)
{
...
try
{
// if a search term exactly equals a SKU or MPN then redirect to that product
// page instead of running the search
var product = _productService.GetExactMatchFromSkuOrMpn(query.Term.Trim());
if (product != null)
{
var url = Url.RouteUrl("Product", new { SeName = product.GetSeName() }, Request.Url.Scheme);
return RedirectPermanent(url);
}
result = _catalogSearchService.Search(query);
}
catch (Exception ex)
{
model.Error = ex.ToString();
result = new CatalogSearchResult(query);
}
...
}