'Magento_Review::helper/summary.phtml', self::SHORT_VIEW => 'Magento_Review::helper/summary_short.phtml', ]; /** * Review model factory * * @var \Magento\Review\Model\ReviewFactory */ protected $_reviewFactory; /** * @param \Magento\Framework\View\Element\Template\Context $context * @param \Magento\Review\Model\ReviewFactory $reviewFactory * @param array $data */ public function __construct( \Magento\Framework\View\Element\Template\Context $context, \Magento\Review\Model\ReviewFactory $reviewFactory, array $data = [] ) { $this->_reviewFactory = $reviewFactory; parent::__construct($context, $data); } /** * Review module availability * * @return string */ public function isReviewEnabled() : string { return $this->_scopeConfig->getValue( PredispatchReviewObserver::XML_PATH_REVIEW_ACTIVE, \Magento\Store\Model\ScopeInterface::SCOPE_STORE ); } /** * Get review summary html * * @param Product $product * @param string $templateType * @param bool $displayIfNoReviews * * @return string */ public function getReviewsSummaryHtml( \Magento\Catalog\Model\Product $product, $templateType = self::DEFAULT_VIEW, $displayIfNoReviews = false ) { if (!$product->getRatingSummary()) { $this->_reviewFactory->create()->getEntitySummary($product, $this->_storeManager->getStore()->getId()); } if (!$product->getRatingSummary() && !$displayIfNoReviews) { return ''; } // pick template among available if (empty($this->_availableTemplates[$templateType])) { $templateType = self::DEFAULT_VIEW; } $this->setTemplate($this->_availableTemplates[$templateType]); $this->setDisplayIfEmpty($displayIfNoReviews); $this->setProduct($product); return $this->toHtml(); } /** * Get ratings summary * * @return string */ public function getRatingSummary() { return $this->getProduct()->getRatingSummary()->getRatingSummary(); } /** * Get count of reviews * * @return int */ public function getReviewsCount() { return $this->getProduct()->getRatingSummary()->getReviewsCount(); } /** * Get review product list url * * @param bool $useDirectLink allows to use direct link for product reviews page * @return string */ public function getReviewsUrl($useDirectLink = false) { $product = $this->getProduct(); if ($useDirectLink) { return $this->getUrl( 'review/product/list', ['id' => $product->getId(), 'category' => $product->getCategoryId()] ); } return $product->getUrlModel()->getUrl($product, ['_ignore_category' => true]); } }