コード例 #1
0
 /**
  * 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;
 }
コード例 #2
0
ファイル: EventTest.php プロジェクト: nja78/magento2
 /**
  * @return void
  */
 public function testClean()
 {
     $eventMock = $this->getMockBuilder('Magento\\Reports\\Model\\Event')->disableOriginalConstructor()->getMock();
     $selectMock = $this->getMockBuilder('Magento\\Framework\\DB\\Select')->disableOriginalConstructor()->setMethods(['select', 'from', 'joinLeft', 'where', 'limit', 'fetchCol'])->getMock();
     $this->connectionMock->expects($this->at(3))->method('fetchCol')->willReturn(1);
     $this->connectionMock->expects($this->once())->method('delete');
     $this->connectionMock->expects($this->any())->method('select')->willReturn($selectMock);
     $selectMock->expects($this->exactly(2))->method('from')->willReturnSelf();
     $selectMock->expects($this->exactly(2))->method('joinLeft')->willReturnSelf();
     $selectMock->expects($this->any())->method('where')->willReturnSelf();
     $selectMock->expects($this->exactly(2))->method('limit')->willReturnSelf();
     $this->event->clean($eventMock);
 }