Advertisement
Guest User

Untitled

a guest
Mar 18th, 2019
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1. $_items = $block->getReviewsCollection()->getItems();
  2.  
  3. public function getReviewsCollection()
  4. {
  5. if (null === $this->_reviewsCollection) {
  6. $this->_reviewsCollection = $this->_reviewsColFactory->create()->addStoreFilter(
  7. $this->_storeManager->getStore()->getId()
  8. )->addStatusFilter(
  9. MagentoReviewModelReview::STATUS_APPROVED
  10. )->addEntityFilter(
  11. 'product',
  12. $this->getProduct()->getId()
  13. )->setDateOrder();
  14. }
  15. return $this->_reviewsCollection;
  16. }
  17.  
  18. foreach ($_items as $_review):
  19. ...
  20. ...
  21. foreach ($_review->getRatingVotes() as $_vote):
  22. ...
  23. ...
  24.  
  25. public function __construct(
  26. MagentoCatalogApiProductRepositoryInterface $productRepository,
  27. MagentoFrameworkRegistry $registry,
  28. MagentoReviewModelResourceModelReviewCollectionFactory $reviewCollection,
  29. MagentoStoreModelStoreManagerInterface $storeManager,
  30. MagentoFrameworkViewElementTemplateContext $context,
  31. array $data = []
  32. ) {
  33. $this->productRepository = $productRepository;
  34. $this->registry = $registry;
  35. $this->reviewCollection = $reviewCollection;
  36. $this->storeManager = $storeManager;
  37. parent::__construct($context, $data);
  38. }
  39.  
  40. public function getCollection()
  41. {
  42. $category = $this->registry->registry('current_category');
  43. $collection = $category->getProductCollection();
  44.  
  45. $latestReviews = [];
  46.  
  47. foreach( $collection as $product ) {
  48.  
  49. $prod = $this->productRepository->getById($product->getId());
  50.  
  51. $urlKey = $prod->getData("url_key");
  52. $url = $this->getUrl($urlKey);
  53.  
  54. $reviewCollection = $this->reviewCollection->create()
  55. ->addStoreFilter(
  56. $this->storeManager->getStore()->getId()
  57. )->addStatusFilter(
  58. MagentoReviewModelReview::STATUS_APPROVED
  59. )->addEntityFilter(
  60. 'product',
  61. $prod->getId()
  62. )->setDateOrder();
  63.  
  64. $reviews = $reviewCollection->getItems();
  65.  
  66. if( !empty($reviews) ){
  67. foreach ($reviews as $review){
  68. foreach( $review->getRatingVotes() as $rating ){
  69. // do stuff here
  70. }
  71. }
  72. }
  73. }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement