Close

Modify Instant Search Response

robinrogne
7 years ago
#13756 Quote
Avatar
  • 11
I need to customize Instant Search plugin for nopcommerce 3.9.
I have hijacked the call to InstantSearch to my own controller, and planning to add a few extra fields in the json response. But can't figure out what my controller should return. I always get error that it can't read property of null.

What should my controller return?
It looks something like this atm.
[HttpGet]
        public ViewResult GetAllCategoriesByProductSearchTerm(string q)
        {
            var path = Url.RouteUrl("InstantSearch");
            var urlBuilder =
            new System.UriBuilder(Request.Url.AbsoluteUri)
            {
                Path = path,
                Query = $"q={HttpUtility.UrlEncode(q)}"
            };
            string url = urlBuilder.ToString();
            var json = new WebClient().DownloadString(urlBuilder.ToString());
            return JArray.Parse(json);          
        }
SDobrev
7 years ago
#13760 Quote
Avatar
  • 283
Hi,

Here is the Action that we are using:


        public ActionResult InstantSearchFor(string q, int categoryId = 0, int manufacturerId = 0, int vendorId = 0)
        {
            List<ProductOverviewModel> searchProductInfos = SearchProducts(q, categoryId, manufacturerId, vendorId);

            return new JsonResult { Data = searchProductInfos, JsonRequestBehavior = JsonRequestBehavior.AllowGet };
        }
Best Regards,
Stoyan Dobrev
Nop-Templates.com