123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\Review\Block\Product;
- use Magento\Catalog\Api\ProductRepositoryInterface;
- use Magento\Review\Model\ResourceModel\Review\Collection as ReviewCollection;
- /**
- * Product Reviews Page
- *
- * @author Magento Core Team <core@magentocommerce.com>
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- */
- class View extends \Magento\Catalog\Block\Product\View
- {
- /**
- * Review collection
- *
- * @var ReviewCollection
- */
- protected $_reviewsCollection;
- /**
- * Review resource model
- *
- * @var \Magento\Review\Model\ResourceModel\Review\CollectionFactory
- */
- protected $_reviewsColFactory;
- /**
- * @param \Magento\Catalog\Block\Product\Context $context
- * @param \Magento\Framework\Url\EncoderInterface $urlEncoder
- * @param \Magento\Framework\Json\EncoderInterface $jsonEncoder
- * @param \Magento\Framework\Stdlib\StringUtils $string
- * @param \Magento\Catalog\Helper\Product $productHelper
- * @param \Magento\Catalog\Model\ProductTypes\ConfigInterface $productTypeConfig
- * @param \Magento\Framework\Locale\FormatInterface $localeFormat
- * @param \Magento\Customer\Model\Session $customerSession
- * @param ProductRepositoryInterface $productRepository
- * @param \Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency
- * @param \Magento\Review\Model\ResourceModel\Review\CollectionFactory $collectionFactory
- * @param array $data
- * @SuppressWarnings(PHPMD.ExcessiveParameterList)
- */
- public function __construct(
- \Magento\Catalog\Block\Product\Context $context,
- \Magento\Framework\Url\EncoderInterface $urlEncoder,
- \Magento\Framework\Json\EncoderInterface $jsonEncoder,
- \Magento\Framework\Stdlib\StringUtils $string,
- \Magento\Catalog\Helper\Product $productHelper,
- \Magento\Catalog\Model\ProductTypes\ConfigInterface $productTypeConfig,
- \Magento\Framework\Locale\FormatInterface $localeFormat,
- \Magento\Customer\Model\Session $customerSession,
- ProductRepositoryInterface $productRepository,
- \Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency,
- \Magento\Review\Model\ResourceModel\Review\CollectionFactory $collectionFactory,
- array $data = []
- ) {
- $this->_reviewsColFactory = $collectionFactory;
- parent::__construct(
- $context,
- $urlEncoder,
- $jsonEncoder,
- $string,
- $productHelper,
- $productTypeConfig,
- $localeFormat,
- $customerSession,
- $productRepository,
- $priceCurrency,
- $data
- );
- }
- /**
- * Render block HTML
- *
- * @return string
- */
- protected function _toHtml()
- {
- $this->getProduct()->setShortDescription(null);
- return parent::_toHtml();
- }
- /**
- * Replace review summary html with more detailed review summary
- * Reviews collection count will be jerked here
- *
- * @param \Magento\Catalog\Model\Product $product
- * @param bool $templateType
- * @param bool $displayIfNoReviews
- * @return string
- * @SuppressWarnings(PHPMD.UnusedFormalParameter)
- */
- public function getReviewsSummaryHtml(
- \Magento\Catalog\Model\Product $product,
- $templateType = false,
- $displayIfNoReviews = false
- ) {
- return $this->getLayout()->createBlock(
- \Magento\Review\Block\Rating\Entity\Detailed::class
- )->setEntityId(
- $this->getProduct()->getId()
- )->toHtml() . $this->getLayout()->getBlock(
- 'product_review_list.count'
- )->assign(
- 'count',
- $this->getReviewsCollection()->getSize()
- )->toHtml();
- }
- /**
- * Get collection of reviews
- *
- * @return ReviewCollection
- */
- public function getReviewsCollection()
- {
- if (null === $this->_reviewsCollection) {
- $this->_reviewsCollection = $this->_reviewsColFactory->create()->addStoreFilter(
- $this->_storeManager->getStore()->getId()
- )->addStatusFilter(
- \Magento\Review\Model\Review::STATUS_APPROVED
- )->addEntityFilter(
- 'product',
- $this->getProduct()->getId()
- )->setDateOrder();
- }
- return $this->_reviewsCollection;
- }
- /**
- * Force product view page behave like without options
- *
- * @return bool
- */
- public function hasOptions()
- {
- return false;
- }
- }
|