12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\Review\Block\Rating\Entity;
- /**
- * Entity rating block
- *
- * @author Magento Core Team <core@magentocommerce.com>
- */
- class Detailed extends \Magento\Framework\View\Element\Template
- {
- /**
- * @var string
- */
- protected $_template = 'Magento_Review::detailed.phtml';
- /**
- * @var \Magento\Review\Model\RatingFactory
- */
- protected $_ratingFactory;
- /**
- * @param \Magento\Framework\View\Element\Template\Context $context
- * @param \Magento\Review\Model\RatingFactory $ratingFactory
- * @param array $data
- */
- public function __construct(
- \Magento\Framework\View\Element\Template\Context $context,
- \Magento\Review\Model\RatingFactory $ratingFactory,
- array $data = []
- ) {
- $this->_ratingFactory = $ratingFactory;
- parent::__construct($context, $data);
- }
- /**
- * Returns block html
- *
- * @return string
- */
- protected function _toHtml()
- {
- $entityId = $this->_request->getParam('id');
- if ((int)$entityId <= 0) {
- return '';
- }
- $reviewsCount = $this->_ratingFactory->create()->getTotalReviews($entityId, true);
- if ($reviewsCount == 0) {
- #return __('Be the first to review this product');
- $this->setTemplate('Magento_Review::empty.phtml');
- return parent::_toHtml();
- }
- $ratingCollection = $this->_ratingFactory->create()->getResourceCollection()->addEntityFilter(
- 'product' # TOFIX
- )->setPositionOrder()->setStoreFilter(
- $this->_storeManager->getStore()->getId()
- )->addRatingPerStoreName(
- $this->_storeManager->getStore()->getId()
- )->load();
- if ($entityId) {
- $ratingCollection->addEntitySummaryToItem($entityId, $this->_storeManager->getStore()->getId());
- }
- $this->assign('collection', $ratingCollection);
- return parent::_toHtml();
- }
- }
|