Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Review.php
Go to the documentation of this file.
1 <?php
7 
10 
18 class Review extends Template implements IdentityInterface
19 {
25  protected $_coreRegistry;
26 
33 
40  public function __construct(
41  \Magento\Framework\View\Element\Template\Context $context,
42  \Magento\Framework\Registry $registry,
43  \Magento\Review\Model\ResourceModel\Review\CollectionFactory $collectionFactory,
44  array $data = []
45  ) {
46  $this->_coreRegistry = $registry;
47  $this->_reviewsColFactory = $collectionFactory;
48  parent::__construct($context, $data);
49 
50  $this->setTabTitle();
51  }
52 
58  public function getProductId()
59  {
60  $product = $this->_coreRegistry->registry('product');
61  return $product ? $product->getId() : null;
62  }
63 
69  public function getProductReviewUrl()
70  {
71  return $this->getUrl(
72  'review/product/listAjax',
73  [
74  '_secure' => $this->getRequest()->isSecure(),
75  'id' => $this->getProductId(),
76  ]
77  );
78  }
79 
85  public function setTabTitle()
86  {
87  $title = $this->getCollectionSize()
88  ? __('Reviews %1', '<span class="counter">' . $this->getCollectionSize() . '</span>')
89  : __('Reviews');
90  $this->setTitle($title);
91  }
92 
98  public function getCollectionSize()
99  {
100  $collection = $this->_reviewsColFactory->create()->addStoreFilter(
101  $this->_storeManager->getStore()->getId()
102  )->addStatusFilter(
103  \Magento\Review\Model\Review::STATUS_APPROVED
104  )->addEntityFilter(
105  'product',
106  $this->getProductId()
107  );
108 
109  return $collection->getSize();
110  }
111 
117  public function getIdentities()
118  {
120  }
121 }
$title
Definition: default.phtml:14
__construct(\Magento\Framework\View\Element\Template\Context $context, \Magento\Framework\Registry $registry, \Magento\Review\Model\ResourceModel\Review\CollectionFactory $collectionFactory, array $data=[])
Definition: Review.php:40
__()
Definition: __.php:13