0

is there any need to override my custom observer.

I have an observer like:

\Vendor\Module\Observer\MyObserver.php

<?php
 namespace Vendor\Module\Observer;
 use \Magento\Framework\Event\Observer;
 use Magento\Framework\Event\ObserverInterface;

 class MyObserver implements ObserverInterface
 {

/**
 * @var \Vendor\Module\Model\EngineFactory
 */
protected $tglssearchEngineFactory;


public function __construct(
    \Vendor\Module\Model\Engine $tglssearchEngineFactory

) {
    $this->tglssearchEngineFactory = $tglssearchEngineFactory;

}

  /*  public function createSearchObject(\Magento\Framework\Event\Observer $observer)
{
    echo 'obssr';
    $this->tglssearchEngineFactory->create()->getCatalogResult();
} 
*/

  public function execute(\Magento\Framework\Event\Observer $observer)
 {
    echo 'obssrexe';
    $event = $observer->getEvent();
    $this->tglssearchEngineFactory->create()->getCatlogSearchResult();
}

 }

etc/frontend/events.xml

<?xml version="1.0"?>
 <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
 <event name="controller_action_predispatch_catalogsearch_result_index">
    <observer name="controller_action_predispatch_catalogsearch_result_handler" instance="vendor\Module\Observer\MyObserver"/> 
</event>
</config>

Is my event name correct?

My router frontname: tgllsearch

Controller name: result

Action: index

Now in my home page, when i try to search for a keyword for a product, the url gets redirected to

http://localhost:1338/magento2x_2/catalogsearch/result/?q=wirel

which i want it as

http://localhost:1338/magento2x_2/tgllsearch/result/?q=wirel

But from : catalogsearch/result/?q=wirel my echo obssrexe is printing.

Should i have to override my Observer

1

I think you need to rewrite controller of Magento_CatalogSearch and not the Observer.

Take a look at this topic : https://magento.stackexchange.com/a/122774/6643.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.