You are a developer and looking for Shopware projects?
Apply Now!
getCustomerReview example
$product
=
$this
->
getRandomProduct
(
$context
)
;
$this
->
createReviews
(
$product
,
$context
)
;
$request
=
new
Request
(
[
]
,
[
]
,
[
'productId' =>
$product
->
getId
(
)
]
)
;
$page
=
$this
->
getPageLoader
(
)
->
load
(
$request
,
$context
)
;
static
::
assertInstanceOf
(
ReviewLoaderResult::
class
,
$page
->
getReviews
(
)
)
;
static
::
assertCount
(
7,
$page
->
getReviews
(
)
)
;
static
::
assertInstanceOf
(
RatingMatrix::
class
,
$page
->
getReviews
(
)
->
getMatrix
(
)
)
;
static
::
assertInstanceOf
(
ProductReviewEntity::
class
,
$page
->
getReviews
(
)
->
getCustomerReview
(
)
)
;
static
::
assertNotNull
(
$context
->
getCustomer
(
)
)
;
static
::
assertEquals
(
$context
->
getCustomer
(
)
->
getId
(
)
,
$page
->
getReviews
(
)
->
getCustomerReview
(
)
->
getCustomerId
(
)
)
;
$matrix
=
$page
->
getReviews
(
)
->
getMatrix
(
)
;
static
::
assertEquals
(
3.429, \
round
(
$matrix
->
getAverageRating
(
)
, 3
)
)
;
static
::
assertEquals
(
7,
$matrix
->
getTotalReviewCount
(
)
)
;
}
public
function
testItLoadsPageWithProductCategoryAsActiveNavigation
(
)
: void
{
$context
=
$this
->
createSalesChannelContextWithLoggedInCustomerAndWithNavigation
(
)
;
$reviewResult
= ReviewLoaderResult::
createFrom
(
$reviews
)
;
$reviewResult
->
setProductId
(
$request
->
get
(
'productId'
)
)
;
$reviewResult
->
setParentId
(
$request
->
get
(
'parentId'
)
)
;
$aggregation
=
$reviews
->
getAggregations
(
)
->
get
(
'ratingMatrix'
)
;
$matrix
=
new
RatingMatrix
(
[
]
)
;
if
(
$aggregation
instanceof TermsResult
)
{
$matrix
=
new
RatingMatrix
(
$aggregation
->
getBuckets
(
)
)
;
}
$reviewResult
->
setMatrix
(
$matrix
)
;
$reviewResult
->
setCustomerReview
(
$this
->
getCustomerReview
(
$productId
,
$context
)
)
;
$reviewResult
->
setTotalReviews
(
$matrix
->
getTotalReviewCount
(
)
)
;
return
$reviewResult
;
}
private
function
createCriteria
(
Request
$request
, SalesChannelContext
$context
)
: Criteria
{
$limit
=
(int)
$request
->
get
(
'limit', self::LIMIT
)
;
$page
=
(int)
$request
->
get
(
'p', self::DEFAULT_PAGE
)
;
$offset
=
$limit
*
(
$page
- 1
)
;
$reviewCriteria
=
$this
->
createReviewCriteria
(
$request
,
$context
)
;
$reviews
=
$this
->productReviewRoute
->
load
(
$product
->
getParentId
(
)
??
$product
->
getId
(
)
,
$request
,
$context
,
$reviewCriteria
)
->
getResult
(
)
;
$matrix
=
$this
->
getReviewRatingMatrix
(
$reviews
)
;
$reviewResult
= ProductReviewResult::
createFrom
(
$reviews
)
;
$reviewResult
->
setMatrix
(
$matrix
)
;
$reviewResult
->
setProductId
(
$product
->
getId
(
)
)
;
$reviewResult
->
setCustomerReview
(
$this
->
getCustomerReview
(
$product
->
getId
(
)
,
$context
)
)
;
$reviewResult
->
setTotalReviews
(
$matrix
->
getTotalReviewCount
(
)
)
;
$reviewResult
->
setProductId
(
$product
->
getId
(
)
)
;
$reviewResult
->
setParentId
(
$product
->
getParentId
(
)
??
$product
->
getId
(
)
)
;
return
$reviewResult
;
}
private
function
createReviewCriteria
(
Request
$request
, SalesChannelContext
$context
)
: Criteria
{
$limit
=
(int)
$request
->
get
(
'limit', self::LIMIT
)
;
$page
=
(int)
$request
->
get
(
'p', self::DEFAULT_PAGE
)
;