Detailed.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Review\Block\Rating\Entity;
  7. /**
  8. * Entity rating block
  9. *
  10. * @author Magento Core Team <core@magentocommerce.com>
  11. */
  12. class Detailed extends \Magento\Framework\View\Element\Template
  13. {
  14. /**
  15. * @var string
  16. */
  17. protected $_template = 'Magento_Review::detailed.phtml';
  18. /**
  19. * @var \Magento\Review\Model\RatingFactory
  20. */
  21. protected $_ratingFactory;
  22. /**
  23. * @param \Magento\Framework\View\Element\Template\Context $context
  24. * @param \Magento\Review\Model\RatingFactory $ratingFactory
  25. * @param array $data
  26. */
  27. public function __construct(
  28. \Magento\Framework\View\Element\Template\Context $context,
  29. \Magento\Review\Model\RatingFactory $ratingFactory,
  30. array $data = []
  31. ) {
  32. $this->_ratingFactory = $ratingFactory;
  33. parent::__construct($context, $data);
  34. }
  35. /**
  36. * Returns block html
  37. *
  38. * @return string
  39. */
  40. protected function _toHtml()
  41. {
  42. $entityId = $this->_request->getParam('id');
  43. if ((int)$entityId <= 0) {
  44. return '';
  45. }
  46. $reviewsCount = $this->_ratingFactory->create()->getTotalReviews($entityId, true);
  47. if ($reviewsCount == 0) {
  48. #return __('Be the first to review this product');
  49. $this->setTemplate('Magento_Review::empty.phtml');
  50. return parent::_toHtml();
  51. }
  52. $ratingCollection = $this->_ratingFactory->create()->getResourceCollection()->addEntityFilter(
  53. 'product' # TOFIX
  54. )->setPositionOrder()->setStoreFilter(
  55. $this->_storeManager->getStore()->getId()
  56. )->addRatingPerStoreName(
  57. $this->_storeManager->getStore()->getId()
  58. )->load();
  59. if ($entityId) {
  60. $ratingCollection->addEntitySummaryToItem($entityId, $this->_storeManager->getStore()->getId());
  61. }
  62. $this->assign('collection', $ratingCollection);
  63. return parent::_toHtml();
  64. }
  65. }