We are using starterstore 2.4.0 in our project for search, PDP and other features.
We are also using Search & Merchandising as our primary search results provider.
As part of the Search & Merchandising functionality, we have implemented “search redirection” so that when users type certain keywords on the search box and hit enter, S&M instead of returning results, returns a redirection URL to which we should redirect users to.
This is the list of commands for the search page:
psmtInitContextCommand, personalizationCallCommand, psmtSearchCommand, psmtProductEnrichmentCommand, pageableCommand, psmtTrackingCommand
Now, the question is: is there an “elegant” way to interrupt that command chain for the cases where we detect that S&M is returning a redirect URL as a consequence of the user’s search input?
psmtSearchCommand is the one that goes to S&M and returns the redirect Urls for these special keywords mentioned before.
Although we detect the S&M response contains that redirection url and perform the redirection accordingly using
{code:java}
exchangeState.getContext().getResponse().sendRedirect(redirectedUrl);
{code}
we noticed that the rest of the commands in the chain get executed anyway. This is clearly a waste of resources since the intention is to send the user to a different page, so nothing that gets executed after the redirection is necessary from our perspective.
Throwing an exception from the code interrupts the chain, but that’s far from elegant.
Is there any other way to accomplish the interruption and prevent the rest of the commands from being executed?
Kind Regards
Juan Manuel