Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
getReviewsCount example
if
(
$productConfig
->
isStatic
(
)
)
{
$product
=
$this
->
getSlotProduct
(
$slot
,
$result
,
$productConfig
->
getStringValue
(
)
)
;
}
/** @var SalesChannelProductEntity|null $product */
if
(
$product
!== null
)
{
$buyBox
->
setProduct
(
$product
)
;
$buyBox
->
setProductId
(
$product
->
getId
(
)
)
;
$buyBox
->
setConfiguratorSettings
(
$this
->configuratorLoader->
load
(
$product
,
$resolverContext
->
getSalesChannelContext
(
)
)
)
;
$buyBox
->
setTotalReviews
(
$this
->
getReviewsCount
(
$product
,
$resolverContext
->
getSalesChannelContext
(
)
)
)
;
}
}
private
function
getReviewsCount
(
SalesChannelProductEntity
$product
, SalesChannelContext
$context
)
: int
{
$reviewCriteria
=
$this
->
createReviewCriteria
(
$context
,
$product
->
getParentId
(
)
??
$product
->
getId
(
)
)
;
$aggregation
=
$this
->repository->
aggregate
(
$reviewCriteria
,
$context
->
getContext
(
)
)
->
get
(
'review-count'
)
;
return
$aggregation
instanceof CountResult ?
$aggregation
->
getCount
(
)
: 0;
}