Moin!
In der Shopware-Suche gibt es in der defaultSearchAction eine Funktion, die bei jeder Suche schaut, ob es dazu eine ‘ordernumber’ gibt und dann direkt den Artikel ausgibt.
// Check if we have a one to one match for ordernumber, then redirect
$location = $this->searchFuzzyCheck($term);
if (!empty($location)) {
return $this->redirect($location);
}
Leider auch dann wenn in der Vorschlagsliste bei der Sucheingabe mehrere Ergebnisse vorhanden sind. Da sich diese Funktion nicht deaktivieren läßt, wollte ich sie mit einem Plugin überschreiben.
/**
* Register events
*/
public function subscribeEvents()
{
$this->subscribeEvent(
'Shopware_Controllers_Frontend_Search::defaultSearchAction::replace',
'replaceDefaultSearchAction'
);
}
/**
* Override defaultSearchAction
*
* @param Enlight_Hook_HookArgs $arguments
*/
public function replaceDefaultSearchAction(Enlight_Hook_HookArgs $arguments)
{
$Controller = $arguments->getSubject();
if (!$Controller->Request()->has('sSort')) {
$Controller->Request()->setParam('sSort', 7);
}
$term = $Controller->getSearchTerm();
$Controller->View()->loadTemplate('frontend/search/fuzzy.tpl');
$minLengthSearchTerm = $Controller->get('config')->get('minSearchLenght');
if (strlen($term) < (int) $minLengthSearchTerm) {
return;
}
/**@var $context ProductContextInterface*/
$context = $Controller->get('shopware_storefront.context_service')->getProductContext();
$criteria = Shopware()->Container()->get('shopware_search.store_front_criteria_factory')
->createSearchCriteria($Controller->Request(), $context);
/**@var $result ProductSearchResult*/
$result = $Controller->get('shopware_search.product_search')->search($criteria, $context);
$articles = $Controller->convertProducts($result);
if ($Controller->get('config')->get('traceSearch', true)) {
$Controller->get('shopware_searchdbal.search_term_logger')->logResult(
$criteria,
$result,
$context->getShop()
);
}
$pageCounts = $Controller->get('config')->get('fuzzySearchSelectPerPage');
$request = $Controller->Request()->getParams();
$request['sSearchOrginal'] = $term;
/** @var $mapper \Shopware\Components\QueryAliasMapper */
$mapper = $Controller->get('query_alias_mapper');
$Controller->View()->assign(array(
'term' => $term,
'criteria' => $criteria,
'facets' => $result->getFacets(),
'sPage' => $Controller->Request()->getParam('sPage', 1),
'sSort' => $Controller->Request()->getParam('sSort', 7),
'sTemplate' => $Controller->Request()->getParam('sTemplate'),
'sPerPage' => array_values(explode("|", $pageCounts)),
'sRequests' => $request,
'shortParameters' => $mapper->getQueryAliases(),
'pageSizes' => array_values(explode("|", $pageCounts)),
'ajaxCountUrlParams' => ['sCategory' => $context->getShop()->getCategory()->getId()],
'sSearchResults' => array(
'sArticles' => $articles,
'sArticlesCount' => $result->getTotalCount()
),
'productBoxLayout' => $Controller->get('config')->get('searchProductBoxLayout')
));
}
Allerdings wirft Shopware einen Fehler:
debug exception 'Enlight_Exception' with message 'Method "Shopware_Proxies_ShopwareControllersFrontendSearchProxy::getSearchTerm" not found failure' in [...]/engine/Shopware/Plugins/Local/Frontend/NldModifiedSearch/Bootstrap.php:106
Stack trace:
#0 [...]/engine/Library/Enlight/Controller/Action.php(393): Enlight_Class->__call('getSearchTerm', Array)
#1 [...]/engine/Shopware/Plugins/Local/Frontend/NldModifiedSearch/Bootstrap.php(106): Enlight_Controller_Action->__call('getSearchTerm', Array)
#2 [...]/engine/Shopware/Plugins/Local/Frontend/NldModifiedSearch/Bootstrap.php(106): Shopware_Proxies_ShopwareControllersFrontendSearchProxy->getSearchTerm()
#3 [...]/engine/Library/Enlight/Event/Handler/Plugin.php(149): Shopware_Plugins_Frontend_NldModifiedSearch_Bootstrap->replaceDefaultSearchAction(Object(Enlight_Hook_HookArgs))
#4 [...]/engine/Library/Enlight/Event/EventManager.php(213): Enlight_Event_Handler_Plugin->execute(Object(Enlight_Hook_HookArgs))
#5 [...]/engine/Library/Enlight/Hook/HookManager.php(187): Enlight_Event_EventManager->notify('Shopware_Contro...', Object(Enlight_Hook_HookArgs))
#6 [...]/var/cache/production_201604081130/proxies/ShopwareControllersFrontendSearchProxy.php(18): Enlight_Hook_HookManager->executeHooks(Object(Shopware_Proxies_ShopwareControllersFrontendSearchProxy), 'defaultSearchAc...', Array)
#7 [...]/engine/Library/Enlight/Controller/Action.php(158): Shopware_Proxies_ShopwareControllersFrontendSearchProxy->defaultSearchAction()
#8 [...]/engine/Library/Enlight/Controller/Dispatcher/Default.php(523): Enlight_Controller_Action->dispatch('defaultSearchAc...')
#9 [...]/engine/Library/Enlight/Controller/Front.php(226): Enlight_Controller_Dispatcher_Default->dispatch(Object(Enlight_Controller_Request_RequestHttp), Object(Enlight_Controller_Response_ResponseHttp))
#10 [...]/engine/Shopware/Kernel.php(153): Enlight_Controller_Front->dispatch()
#11 [...]/vendor/symfony/http-kernel/HttpCache/HttpCache.php(492): Shopware\Kernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#12 [...]/engine/Shopware/Components/HttpCache/AppCache.php(255): Symfony\Component\HttpKernel\HttpCache\HttpCache->forward(Object(Symfony\Component\HttpFoundation\Request), true, NULL)
#13 [...]/vendor/symfony/http-kernel/HttpCache/HttpCache.php(449): Shopware\Components\HttpCache\AppCache->forward(Object(Symfony\Component\HttpFoundation\Request), true)
#14 [...]/vendor/symfony/http-kernel/HttpCache/HttpCache.php(349): Symfony\Component\HttpKernel\HttpCache\HttpCache->fetch(Object(Symfony\Component\HttpFoundation\Request), true)
#15 [...]/engine/Shopware/Components/HttpCache/AppCache.php(178): Symfony\Component\HttpKernel\HttpCache\HttpCache->lookup(Object(Symfony\Component\HttpFoundation\Request), true)
#16 [...]/vendor/symfony/http-kernel/HttpCache/HttpCache.php(213): Shopware\Components\HttpCache\AppCache->lookup(Object(Symfony\Component\HttpFoundation\Request), true)
#17 [...]/engine/Shopware/Components/HttpCache/AppCache.php(114): Symfony\Component\HttpKernel\HttpCache\HttpCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#18 [...]/shopware.php(108): Shopware\Components\HttpCache\AppCache->handle(Object(Symfony\Component\HttpFoundation\Request))
#19 {main}
Nun verstehe ich nicht, warum die getSearchTerm nicht gefunden wird. Die Klasse des Controllers sollte doch mit $Controller = $arguments->getSubject(); angesprochen werden können…
Weiß vielleicht jemand Rat?
Grüße
Thorsten