Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
getSearchTerm example
return
$this
->
forward
(
'defaultSearch'
)
;
}
/** * Default search */
public
function
defaultSearchAction
(
)
{
$this
->
setDefaultSorting
(
)
;
$term
=
$this
->
getSearchTerm
(
)
;
// Check if we have a one to one match for order number, then redirect
$location
=
$this
->
searchFuzzyCheck
(
$term
)
;
if
(
!
empty
(
$location
)
)
{
$this
->
redirect
(
$location
)
;
return
;
}
$this
->
View
(
)
->
loadTemplate
(
'frontend/search/fuzzy.tpl'
)
;
$request
=
new
Request
(
[
'search' => self::TEST_TERM
]
)
;
$context
=
$this
->
createSalesChannelContextWithNavigation
(
)
;
/** @var SearchPageLoadedEvent $homePageLoadedEvent */
$homePageLoadedEvent
= null;
$this
->
catchEvent
(
SearchPageLoadedEvent::
class
,
$homePageLoadedEvent
)
;
$page
=
$this
->
getPageLoader
(
)
->
load
(
$request
,
$context
)
;
static
::
assertInstanceOf
(
SearchPage::
class
,
$page
)
;
static
::
assertEmpty
(
$page
->
getListing
(
)
)
;
static
::
assertSame
(
self::TEST_TERM,
$page
->
getSearchTerm
(
)
)
;
self::
assertPageEvent
(
SearchPageLoadedEvent::
class
,
$homePageLoadedEvent
,
$context
,
$request
,
$page
)
;
}
public
function
testItDoesApplyDefaultSorting
(
)
: void
{
$request
=
new
Request
(
[
'search' => self::TEST_TERM
]
)
;
$context
=
$this
->
createSalesChannelContextWithNavigation
(
)
;
/** @var SearchPageLoadedEvent $homePageLoadedEvent */
$homePageLoadedEvent
= null;