Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
View.php
Go to the documentation of this file.
1 <?php
7 
10 
18 {
25 
32 
48  public function __construct(
49  \Magento\Catalog\Block\Product\Context $context,
50  \Magento\Framework\Url\EncoderInterface $urlEncoder,
51  \Magento\Framework\Json\EncoderInterface $jsonEncoder,
52  \Magento\Framework\Stdlib\StringUtils $string,
53  \Magento\Catalog\Helper\Product $productHelper,
55  \Magento\Framework\Locale\FormatInterface $localeFormat,
56  \Magento\Customer\Model\Session $customerSession,
59  \Magento\Review\Model\ResourceModel\Review\CollectionFactory $collectionFactory,
60  array $data = []
61  ) {
62  $this->_reviewsColFactory = $collectionFactory;
63  parent::__construct(
64  $context,
66  $jsonEncoder,
67  $string,
68  $productHelper,
70  $localeFormat,
74  $data
75  );
76  }
77 
83  protected function _toHtml()
84  {
85  $this->getProduct()->setShortDescription(null);
86 
87  return parent::_toHtml();
88  }
89 
100  public function getReviewsSummaryHtml(
101  \Magento\Catalog\Model\Product $product,
102  $templateType = false,
103  $displayIfNoReviews = false
104  ) {
105  return $this->getLayout()->createBlock(
106  \Magento\Review\Block\Rating\Entity\Detailed::class
107  )->setEntityId(
108  $this->getProduct()->getId()
109  )->toHtml() . $this->getLayout()->getBlock(
110  'product_review_list.count'
111  )->assign(
112  'count',
113  $this->getReviewsCollection()->getSize()
114  )->toHtml();
115  }
116 
122  public function getReviewsCollection()
123  {
124  if (null === $this->_reviewsCollection) {
125  $this->_reviewsCollection = $this->_reviewsColFactory->create()->addStoreFilter(
126  $this->_storeManager->getStore()->getId()
127  )->addStatusFilter(
128  \Magento\Review\Model\Review::STATUS_APPROVED
129  )->addEntityFilter(
130  'product',
131  $this->getProduct()->getId()
132  )->setDateOrder();
133  }
135  }
136 
142  public function hasOptions()
143  {
144  return false;
145  }
146 }
__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=[])
Definition: View.php:48
getReviewsSummaryHtml(\Magento\Catalog\Model\Product $product, $templateType=false, $displayIfNoReviews=false)
Definition: View.php:100
$templateType
Definition: list.phtml:37