/** * @param string $name * @param string $primaryFieldName * @param string $requestFieldName * @param CollectionFactory $collectionFactory * @param RequestInterface $request * @param array $meta * @param array $data */ public function __construct($name, $primaryFieldName, $requestFieldName, CollectionFactory $collectionFactory, RequestInterface $request, array $meta = [], array $data = []) { parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data); $this->collectionFactory = $collectionFactory; $this->collection = $this->collectionFactory->create(); $this->request = $request; }
protected function setUp() { $this->objectManager = new ObjectManager($this); $this->collectionFactoryMock = $this->getMockBuilder(CollectionFactory::class)->setMethods(['create'])->disableOriginalConstructor()->getMock(); $this->collectionMock = $this->objectManager->getCollectionMock(Collection::class, []); $this->requestMock = $this->getMockBuilder(RequestInterface::class)->getMockForAbstractClass(); $this->collectionFactoryMock->expects($this->any())->method('create')->willReturn($this->collectionMock); $this->model = $this->objectManager->getObject(ReviewDataProvider::class, ['name' => 'testName', 'primaryFieldName' => 'testPrimaryFieldName', 'requestFieldName' => 'testRequestFieldName', 'meta' => [], 'data' => [], 'collectionFactory' => $this->collectionFactoryMock, 'request' => $this->requestMock]); }
/** * Return collection of reviews * * @return array|\Magento\Review\Model\ResourceModel\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\ResourceModel\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(); }