Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
ProductPageCriteriaEvent example
if
(
!
$productId
)
{
throw
RoutingException::
missingRequestParameter
(
'productId', '/productId'
)
;
}
$criteria
=
(
new
Criteria
(
)
)
->
addAssociation
(
'manufacturer.media'
)
->
addAssociation
(
'options.group'
)
->
addAssociation
(
'properties.group'
)
->
addAssociation
(
'mainCategories.category'
)
->
addAssociation
(
'media'
)
;
$this
->eventDispatcher->
dispatch
(
new
ProductPageCriteriaEvent
(
$productId
,
$criteria
,
$context
)
)
;
$result
=
$this
->productDetailRoute->
load
(
$productId
,
$request
,
$context
,
$criteria
)
;
$product
=
$result
->
getProduct
(
)
;
if
(
$product
->
getMedia
(
)
)
{
$product
->
getMedia
(
)
->
sort
(
fn
(
ProductMediaEntity
$a
, ProductMediaEntity
$b
)
=>
$a
->
getPosition
(
)
<=>
$b
->
getPosition
(
)
)
;
}
if
(
$product
->
getMedia
(
)
&&
$product
->
getCover
(
)
)
{
$product
->
setMedia
(
new
ProductMediaCollection
(
array_merge
(
[
$product
->
getCover
(
)
->
getId
(
)
=>
$product
->
getCover
(
)
]
,