/** * Retrieve item collection * * @return mixed */ public function getItemCollection() { $productCollection = $this->getData('item_collection'); if ($productCollection === null) { // get products to skip $skipProducts = []; if ($collection = $this->getCreateOrderModel()->getCustomerCompareList()) { $collection = $collection->getItemCollection()->useProductItem(true)->setStoreId($this->getStoreId())->setCustomerId($this->getCustomerId())->load(); foreach ($collection as $_item) { $skipProducts[] = $_item->getProductId(); } } // prepare products collection and apply visitors log to it $productCollection = $this->_productFactory->create()->getCollection()->setStoreId($this->getQuote()->getStoreId())->addStoreFilter($this->getQuote()->getStoreId())->addAttributeToSelect('name')->addAttributeToSelect('price')->addAttributeToSelect('small_image'); $this->_event->applyLogToCollection($productCollection, \Magento\Reports\Model\Event::EVENT_PRODUCT_COMPARE, $this->getCustomerId(), 0, $skipProducts); $productCollection->load(); $this->setData('item_collection', $productCollection); } return $productCollection; }
/** * @return void */ public function testApplyLogToCollection() { $derivedSelect = 'SELECT * FROM table'; $idFieldName = 'IdFieldName'; $collectionSelectMock = $this->getMockBuilder('Magento\\Framework\\DB\\Select')->disableOriginalConstructor()->setMethods(['joinInner', 'order'])->getMock(); $collectionSelectMock->expects($this->once())->method('joinInner')->with(['evt' => new \Zend_Db_Expr("({$derivedSelect})")], "{$idFieldName} = evt.object_id", [])->willReturnSelf(); $collectionSelectMock->expects($this->once())->method('order')->willReturnSelf(); $collectionMock = $this->getMockBuilder('Magento\\Framework\\Data\\Collection\\AbstractDb')->disableOriginalConstructor()->getMock(); $collectionMock->expects($this->once())->method('getResource')->willReturnSelf(); $collectionMock->expects($this->once())->method('getIdFieldName')->willReturn($idFieldName); $collectionMock->expects($this->any())->method('getSelect')->willReturn($collectionSelectMock); $selectMock = $this->getMockBuilder('Magento\\Framework\\DB\\Select')->disableOriginalConstructor()->setMethods(['from', 'where', 'group', 'joinInner', '__toString'])->getMock(); $selectMock->expects($this->once())->method('from')->willReturnSelf(); $selectMock->expects($this->any())->method('where')->willReturnSelf(); $selectMock->expects($this->once())->method('group')->willReturnSelf(); $selectMock->expects($this->any())->method('__toString')->willReturn($derivedSelect); $this->connectionMock->expects($this->once())->method('select')->willReturn($selectMock); $this->storeMock->expects($this->any())->method('getId')->willReturn(1); $this->event->applyLogToCollection($collectionMock, 1, 1, 1); }