/**
  * Perform operations after collection load
  *
  * @return void
  */
 protected function afterLoad()
 {
     if ($this->getSearchCriteria()->getPart('first_store_flag')) {
         $items = $this->searchResultProcessor->getColumnValues($this->linkFieldName);
         $connection = $this->getQuery()->getConnection();
         $resource = $this->getQuery()->getResource();
         if (count($items)) {
             $select = $connection->select()->from(['cps' => $resource->getTable($this->storeTableName)])->where("cps.{$this->linkFieldName} IN (?)", $items);
             $result = $connection->fetchPairs($select);
             if ($result) {
                 foreach ($this->getItems() as $item) {
                     /** @var BlockInterface $item */
                     if (!isset($result[$item->getId()])) {
                         continue;
                     }
                     if ($result[$item->getId()] == 0) {
                         $stores = $this->storeManager->getStores(false, true);
                         $storeId = current($stores)->getId();
                         $storeCode = key($stores);
                     } else {
                         $storeId = $result[$item->getId()];
                         $storeCode = $this->storeManager->getStore($storeId)->getCode();
                     }
                     $item->setData('_first_store_id', $storeId);
                     $item->setData('store_code', $storeCode);
                     $item->setData('store_id', [$result[$item->getId()]]);
                 }
             }
         }
     }
     parent::afterLoad();
 }
 public function testGetItemByColumnValue()
 {
     $columnKey = 'columnKey';
     $columnValue = 'columnValue';
     $columnValue2 = 'columnValue2';
     $itemData = ['id' => 1, $columnKey => $columnValue];
     $itemData2 = ['id' => 2, $columnKey => $columnValue2];
     $testItem = new \Magento\Framework\DataObject($itemData);
     $testItem2 = new \Magento\Framework\DataObject($itemData2);
     $this->searchResultCollectionMock->expects($this->once())->method('getItems')->willReturn([$testItem, $testItem2]);
     $this->assertEquals($testItem2, $this->searchResultProcessor->getItemByColumnValue($columnKey, $columnValue2));
 }