/** * Return collection of reviews * * @return array|\Magento\Review\Model\Resource\Review\Product\Collection */ public function getReviews() { if (!($customerId = $this->currentCustomer->getCustomerId())) { return []; } if (!$this->_collection) { $this->_collection = $this->_collectionFactory->create(); $this->_collection->addStoreFilter($this->_storeManager->getStore()->getId())->addCustomerFilter($customerId)->setDateOrder()->setPageSize(5)->load()->addReviewSummary(); } return $this->_collection; }
/** * Prepare collection * * @return \Magento\Review\Block\Adminhtml\Grid */ protected function _prepareCollection() { /** @var $model \Magento\Review\Model\Review */ $model = $this->_reviewFactory->create(); /** @var $collection \Magento\Review\Model\Resource\Review\Product\Collection */ $collection = $this->_productsFactory->create(); if ($this->getProductId() || $this->getRequest()->getParam('productId', false)) { $productId = $this->getProductId(); if (!$productId) { $productId = $this->getRequest()->getParam('productId'); } $this->setProductId($productId); $collection->addEntityFilter($this->getProductId()); } if ($this->getCustomerId() || $this->getRequest()->getParam('customerId', false)) { $customerId = $this->getCustomerId(); if (!$customerId) { $customerId = $this->getRequest()->getParam('customerId'); } $this->setCustomerId($customerId); $collection->addCustomerFilter($this->getCustomerId()); } if ($this->_coreRegistry->registry('usePendingFilter') === true) { $collection->addStatusFilter($model->getPendingStatus()); } $collection->addStoreData(); $this->setCollection($collection); return parent::_prepareCollection(); }
/** * Get product collection * * @return ProductCollection */ public function getProductCollection() { return $this->productCollectionFactory->create(); }
/** * Initialize review collection * * @return $this */ protected function _initCollection() { $this->_collection = $this->_collectionFactory->create(); $this->_collection->addStoreFilter($this->_storeManager->getStore()->getId())->addCustomerFilter($this->currentCustomer->getCustomerId())->setDateOrder(); return $this; }