_ratingsFactory = $ratingsFactory; $this->_votesFactory = $votesFactory; $this->_coreRegistry = $registry; parent::__construct($context, $data); } /** * Initialize review data * * @return void */ protected function _construct() { parent::_construct(); if ($this->_coreRegistry->registry('review_data')) { $this->setReviewId($this->_coreRegistry->registry('review_data')->getReviewId()); } } /** * Get collection of ratings * * @return RatingCollection */ public function getRating() { if (!$this->getRatingCollection()) { if ($this->_coreRegistry->registry('review_data')) { $stores = $this->_coreRegistry->registry('review_data')->getStores(); $stores = array_diff($stores, [0]); $ratingCollection = $this->_ratingsFactory->create()->addEntityFilter( 'product' )->setStoreFilter( $stores )->setActiveFilter( true )->setPositionOrder()->load()->addOptionToItems(); $this->_voteCollection = $this->_votesFactory->create()->setReviewFilter( $this->getReviewId() )->addOptionInfo()->load()->addRatingOptions(); } elseif (!$this->getIsIndependentMode()) { $ratingCollection = $this->_ratingsFactory->create()->addEntityFilter( 'product' )->setStoreFilter( null )->setPositionOrder()->load()->addOptionToItems(); } else { $stores = $this->getRequest()->getParam('select_stores') ?: $this->getRequest()->getParam('stores'); $ratingCollection = $this->_ratingsFactory->create()->addEntityFilter( 'product' )->setStoreFilter( $stores )->setPositionOrder()->load()->addOptionToItems(); if ((int)$this->getRequest()->getParam('id')) { $this->_voteCollection = $this->_votesFactory->create()->setReviewFilter( (int)$this->getRequest()->getParam('id') )->addOptionInfo()->load()->addRatingOptions(); } } $this->setRatingCollection($ratingCollection->getSize() ? $ratingCollection : false); } return $this->getRatingCollection(); } /** * Set independent mode * * @return $this */ public function setIndependentMode() { $this->setIsIndependentMode(true); return $this; } /** * Indicator of whether or not a rating is selected * * @param Option $option * @param \Magento\Review\Model\Rating $rating * @return bool * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function isSelected($option, $rating) { if ($this->getIsIndependentMode()) { $ratings = $this->getRequest()->getParam('ratings'); if (isset($ratings[$option->getRatingId()])) { return $option->getId() == $ratings[$option->getRatingId()]; } elseif (!$this->_voteCollection) { return false; } } if ($this->_voteCollection) { foreach ($this->_voteCollection as $vote) { if ($option->getId() == $vote->getOptionId()) { return true; } } } return false; } }