CodeExplorer 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
);