|
17 | 17 | use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria; |
18 | 18 | use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsAnyFilter; |
19 | 19 | use Shopware\Core\Framework\DataAbstractionLayer\Search\Sorting\FieldSorting; |
| 20 | +use Shopware\Core\Framework\Struct\ArrayStruct; |
20 | 21 | use Shopware\Core\Framework\Uuid\Uuid; |
21 | 22 | use Shopware\Core\System\CustomField\CustomFieldCollection; |
22 | 23 | use Shopware\Core\System\SalesChannel\SalesChannelContext; |
@@ -123,10 +124,10 @@ public function loadProductCompareData(ProductListingResult $products, SalesChan |
123 | 124 | /** @var SalesChannelProductEntity $product */ |
124 | 125 | foreach ($products as $product) { |
125 | 126 | if ($reviewAllowed) { |
126 | | - $product->setProductReviews($this->loadProductReviews($product, $context)); |
| 127 | + $product->addExtension('productReviews', new ArrayStruct(['reviewTotal' => $this->loadProductReviewCount($product, $context)])); |
127 | 128 | } else { |
128 | 129 | $product->setRatingAverage(null); |
129 | | - $product->setProductReviews(new ProductReviewCollection()); |
| 130 | + $product->addExtension('productReviews', new ArrayStruct(['reviewTotal' => 0])); |
130 | 131 | } |
131 | 132 |
|
132 | 133 | $sortedProperties = $this->sortProperties($product, $selectedPropertyIds); |
@@ -264,18 +265,17 @@ private function getGroupByProperty(array $sorted, PropertyGroupOptionEntity $op |
264 | 265 | return PropertyGroupEntity::createFrom($option->getGroup()); |
265 | 266 | } |
266 | 267 |
|
267 | | - private function loadProductReviews(SalesChannelProductEntity $product, SalesChannelContext $context): ProductReviewCollection |
268 | | - { |
| 268 | + private function loadProductReviewCount(SalesChannelProductEntity $product, SalesChannelContext $context): int { |
269 | 269 | $request = new Request(); |
270 | 270 | $request->request->set('parentId', $product->getParentId()); |
271 | 271 | $request->request->set('productId', $product->getId()); |
272 | | - $reviews = $this->productReviewLoader->load($request, $context)->getEntities(); |
| 272 | + $reviews = $this->productReviewLoader->load($request, $context); |
273 | 273 |
|
274 | | - if ($reviews instanceof ProductReviewCollection) { |
275 | | - return $reviews; |
| 274 | + if ($reviews->getEntities() instanceof ProductReviewCollection) { |
| 275 | + return $reviews->getTotalReviews(); |
276 | 276 | } |
277 | 277 |
|
278 | | - return new ProductReviewCollection(); |
| 278 | + return 0; |
279 | 279 | } |
280 | 280 |
|
281 | 281 | private function loadCustomFields(SalesChannelContext $context, ProductCollection $products): CustomFieldCollection |
|
0 commit comments