View.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Review\Block\Product;
  7. use Magento\Catalog\Api\ProductRepositoryInterface;
  8. use Magento\Review\Model\ResourceModel\Review\Collection as ReviewCollection;
  9. /**
  10. * Product Reviews Page
  11. *
  12. * @author Magento Core Team <core@magentocommerce.com>
  13. * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
  14. */
  15. class View extends \Magento\Catalog\Block\Product\View
  16. {
  17. /**
  18. * Review collection
  19. *
  20. * @var ReviewCollection
  21. */
  22. protected $_reviewsCollection;
  23. /**
  24. * Review resource model
  25. *
  26. * @var \Magento\Review\Model\ResourceModel\Review\CollectionFactory
  27. */
  28. protected $_reviewsColFactory;
  29. /**
  30. * @param \Magento\Catalog\Block\Product\Context $context
  31. * @param \Magento\Framework\Url\EncoderInterface $urlEncoder
  32. * @param \Magento\Framework\Json\EncoderInterface $jsonEncoder
  33. * @param \Magento\Framework\Stdlib\StringUtils $string
  34. * @param \Magento\Catalog\Helper\Product $productHelper
  35. * @param \Magento\Catalog\Model\ProductTypes\ConfigInterface $productTypeConfig
  36. * @param \Magento\Framework\Locale\FormatInterface $localeFormat
  37. * @param \Magento\Customer\Model\Session $customerSession
  38. * @param ProductRepositoryInterface $productRepository
  39. * @param \Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency
  40. * @param \Magento\Review\Model\ResourceModel\Review\CollectionFactory $collectionFactory
  41. * @param array $data
  42. * @SuppressWarnings(PHPMD.ExcessiveParameterList)
  43. */
  44. public function __construct(
  45. \Magento\Catalog\Block\Product\Context $context,
  46. \Magento\Framework\Url\EncoderInterface $urlEncoder,
  47. \Magento\Framework\Json\EncoderInterface $jsonEncoder,
  48. \Magento\Framework\Stdlib\StringUtils $string,
  49. \Magento\Catalog\Helper\Product $productHelper,
  50. \Magento\Catalog\Model\ProductTypes\ConfigInterface $productTypeConfig,
  51. \Magento\Framework\Locale\FormatInterface $localeFormat,
  52. \Magento\Customer\Model\Session $customerSession,
  53. ProductRepositoryInterface $productRepository,
  54. \Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency,
  55. \Magento\Review\Model\ResourceModel\Review\CollectionFactory $collectionFactory,
  56. array $data = []
  57. ) {
  58. $this->_reviewsColFactory = $collectionFactory;
  59. parent::__construct(
  60. $context,
  61. $urlEncoder,
  62. $jsonEncoder,
  63. $string,
  64. $productHelper,
  65. $productTypeConfig,
  66. $localeFormat,
  67. $customerSession,
  68. $productRepository,
  69. $priceCurrency,
  70. $data
  71. );
  72. }
  73. /**
  74. * Render block HTML
  75. *
  76. * @return string
  77. */
  78. protected function _toHtml()
  79. {
  80. $this->getProduct()->setShortDescription(null);
  81. return parent::_toHtml();
  82. }
  83. /**
  84. * Replace review summary html with more detailed review summary
  85. * Reviews collection count will be jerked here
  86. *
  87. * @param \Magento\Catalog\Model\Product $product
  88. * @param bool $templateType
  89. * @param bool $displayIfNoReviews
  90. * @return string
  91. * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  92. */
  93. public function getReviewsSummaryHtml(
  94. \Magento\Catalog\Model\Product $product,
  95. $templateType = false,
  96. $displayIfNoReviews = false
  97. ) {
  98. return $this->getLayout()->createBlock(
  99. \Magento\Review\Block\Rating\Entity\Detailed::class
  100. )->setEntityId(
  101. $this->getProduct()->getId()
  102. )->toHtml() . $this->getLayout()->getBlock(
  103. 'product_review_list.count'
  104. )->assign(
  105. 'count',
  106. $this->getReviewsCollection()->getSize()
  107. )->toHtml();
  108. }
  109. /**
  110. * Get collection of reviews
  111. *
  112. * @return ReviewCollection
  113. */
  114. public function getReviewsCollection()
  115. {
  116. if (null === $this->_reviewsCollection) {
  117. $this->_reviewsCollection = $this->_reviewsColFactory->create()->addStoreFilter(
  118. $this->_storeManager->getStore()->getId()
  119. )->addStatusFilter(
  120. \Magento\Review\Model\Review::STATUS_APPROVED
  121. )->addEntityFilter(
  122. 'product',
  123. $this->getProduct()->getId()
  124. )->setDateOrder();
  125. }
  126. return $this->_reviewsCollection;
  127. }
  128. /**
  129. * Force product view page behave like without options
  130. *
  131. * @return bool
  132. */
  133. public function hasOptions()
  134. {
  135. return false;
  136. }
  137. }