Frontend
Search
Result Landing Page (SRLP) URL
7min
change default srlp url the search result landing page (srlp) url in magento (without any changes) is /catalogsearch/result in v2 x/v3 x version of the klevu module an extra srlp route was added with a url of /search having 2 routes is not ideal in v4 x there is only one search route and by default, that route is the same as the magento default, i e /catalogsearch/result in v2 x/v3 x it was possible to switch between the 2 srlp urls to compare the search results from klevu and native magento this can still be done by adding ?klevu layout preview=klevu or ?klevu layout preview=native to the srlp url note all examples below use module vendor module update to match your module how to create a module 1\ create the route create a new route so magento directs the request to your module vendor/module/etc/frontend/routes xml \<?xml version="1 0"?> \<config xmlns\ xsi="http //www w3 org/2001/xmlschema instance" xsi\ nonamespaceschemalocation="urn\ magento\ framework\ app/etc/routes xsd"> \<router id="standard"> \<route id="catalogsearch" frontname="your search url"> \<module name="vendor module" before="klevu frontendsearch"/> \</route> \</router> \</config> the route id must be catalogsearch the route frontname is your new search url, replace your search url with your desired url \<module must set before="klevu frontendsearch" to replace config in the module klevu frontendsearch also ensure your module xml has a dependency on klevu frontendsearch 2\ define the controller name pass the controller name to the landingurlprovider this handles the second part of the request url without this, the klevu plugin will not provide the correct srlp url to klevu when triggering the search vendor/module/etc/di xml \<?xml version="1 0"?> \<config xmlns\ xsi="http //www w3 org/2001/xmlschema instance" xsi\ nonamespaceschemalocation="urn\ magento\ framework\ objectmanager/etc/config xsd"> \<type name="klevu\frontendsearch\service\provider\landingurlprovider"> \<arguments> \<argument name="controllername" xsi\ type="string">controller name change me\</argument> \</arguments> \</type> \</config> controllername is the directory containing the action i e $this >request >getcontrollername() by default controllername is result this directs requests to the controller controller/result/index php i e your site/catalogsearch/result if using index as the controllername you can pass / as the controllername argument e g controller/index/index php i e your site/search 3\ inject conditions to check if enabled if no conditions are provided then the is enabled check will return true vendor/module/etc/di xml \<type name="klevu\frontendsearch\controller\result\index"> \<arguments> \<argument name="logger" xsi\ type="object">klevu\indexing\logger\logger\</argument> \<argument name="isenabledconditions" xsi\ type="array"> \<item name="klevu integrated" xsi\ type="object">klevu\frontend\service\isenabledcondition\isstoreintegratedcondition\</item> \<item name="klevu modules enabled" xsi\ type="array"> \<item name="klevu srlp enabled" xsi\ type="object">klevu\frontendsearch\service\isenabledcondition\issrlpenabledcondition\</item> \</item> \</argument> \</arguments> \</type> 4\ create a controller to handle the request vendor/module/controller/controllernamechangeme/index php \<?php declare(strict types=1); namespace vendor\module\controller\controllernamechangeme; use klevu\frontend\exception\invalidisenableddeterminerexception; use klevu\frontend\exception\outputdisabledexception; use klevu\frontendapi\service\isenableddeterminerinterface; use klevu\frontendsearch\service\provider\querytextproviderinterface; use magento\catalog\model\layer\resolver; use magento\catalog\model\session; use magento\catalogsearch\controller\result\index as catalogsearchresultindex; use magento\framework\app\action\context; use magento\framework\app\state as appstate; use magento\framework\escaper; use magento\framework\exception\localizedexception; use magento\search\model\queryfactory; use magento\store\model\storemanagerinterface; use psr\log\loggerinterface; class index extends catalogsearchresultindex implements httpgetactioninterface, httppostactioninterface { / @var querytextproviderinterface / private querytextproviderinterface $querytextprovider; public function construct( context $context, session $catalogsession, storemanagerinterface $storemanager, queryfactory $queryfactory, resolver $layerresolver, querytextproviderinterface $querytextprovider, escaper $escaper, loggerinterface $logger, appstate $appstate, isenableddeterminerinterface $isenableddeterminer, array $isenabledconditions = \[], ) { parent construct( context $context, catalogsession $catalogsession, storemanager $storemanager, queryfactory $queryfactory, layerresolver $layerresolver, ); $this >querytextprovider = $querytextprovider; $this >escaper = $escaper; $this >logger = $logger; $this >appstate = $appstate; $this >isenableddeterminer = $isenableddeterminer; $this >isenabledconditions = $isenabledconditions; } / @return void / public function execute() { if (!$this >isklevuenabled()) { parent execute(); return; } $this >setpagetitle(); $this > view >renderlayout(); } / @return void / private function setpagetitle() void { $query = $this >querytextprovider >get(); $this > view >loadlayout(); $page = $this > view >getpage(); $config = $page >getconfig(); $title = $config >gettitle(); $title >set( ("search results for '%1'", $query) >render(), ); } / @return bool @throws invalidisenableddeterminerexception / private function isklevuenabled() bool { $return = false; try { $this >isenableddeterminer >executeand($this >isenabledconditions); $return = true; } catch (invalidisenableddeterminerexception $exception) { if ($this >appstate >getmode() !== appstate mode production) { throw $exception; } $this >logger >error( message 'method {method}, error {error}', context \[ 'method' => method , 'error' => $exception >getmessage(), ], ); } catch (outputdisabledexception) { // output is disabled } return $return; } } change controllernamechangeme in the controller path and namespace to match that set in landingurlprovider controllername argument in etc/di xml (see previous step)