Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $_items = $block->getReviewsCollection()->getItems();
- public function getReviewsCollection()
- {
- if (null === $this->_reviewsCollection) {
- $this->_reviewsCollection = $this->_reviewsColFactory->create()->addStoreFilter(
- $this->_storeManager->getStore()->getId()
- )->addStatusFilter(
- MagentoReviewModelReview::STATUS_APPROVED
- )->addEntityFilter(
- 'product',
- $this->getProduct()->getId()
- )->setDateOrder();
- }
- return $this->_reviewsCollection;
- }
- foreach ($_items as $_review):
- ...
- ...
- foreach ($_review->getRatingVotes() as $_vote):
- ...
- ...
- public function __construct(
- MagentoCatalogApiProductRepositoryInterface $productRepository,
- MagentoFrameworkRegistry $registry,
- MagentoReviewModelResourceModelReviewCollectionFactory $reviewCollection,
- MagentoStoreModelStoreManagerInterface $storeManager,
- MagentoFrameworkViewElementTemplateContext $context,
- array $data = []
- ) {
- $this->productRepository = $productRepository;
- $this->registry = $registry;
- $this->reviewCollection = $reviewCollection;
- $this->storeManager = $storeManager;
- parent::__construct($context, $data);
- }
- public function getCollection()
- {
- $category = $this->registry->registry('current_category');
- $collection = $category->getProductCollection();
- $latestReviews = [];
- foreach( $collection as $product ) {
- $prod = $this->productRepository->getById($product->getId());
- $urlKey = $prod->getData("url_key");
- $url = $this->getUrl($urlKey);
- $reviewCollection = $this->reviewCollection->create()
- ->addStoreFilter(
- $this->storeManager->getStore()->getId()
- )->addStatusFilter(
- MagentoReviewModelReview::STATUS_APPROVED
- )->addEntityFilter(
- 'product',
- $prod->getId()
- )->setDateOrder();
- $reviews = $reviewCollection->getItems();
- if( !empty($reviews) ){
- foreach ($reviews as $review){
- foreach( $review->getRatingVotes() as $rating ){
- // do stuff here
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement