Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Fulltext.php
Go to the documentation of this file.
1 <?php
7 
11 
19 {
25  protected $_eventManager;
26 
32  private $metadataPool;
33 
40  public function __construct(
41  \Magento\Framework\Model\ResourceModel\Db\Context $context,
42  \Magento\Framework\Event\ManagerInterface $eventManager,
43  $connectionName = null,
44  MetadataPool $metadataPool = null
45  ) {
46  $this->_eventManager = $eventManager;
47  $this->metadataPool = $metadataPool ? : ObjectManager::getInstance()->get(MetadataPool::class);
48  parent::__construct($context, $connectionName);
49  }
50 
56  protected function _construct()
57  {
58  $this->_init('catalogsearch_fulltext', 'product_id');
59  }
60 
68  public function resetSearchResults()
69  {
70  $connection = $this->getConnection();
71  $connection->update($this->getTable('search_query'), ['is_processed' => 0], ['is_processed != 0']);
72  $this->_eventManager->dispatch('catalogsearch_reset_search_result');
73  return $this;
74  }
75 
83  {
84  $storeId = (int) $storeId;
85  $connection = $this->getConnection();
86  $connection->update(
87  $this->getTable('search_query'),
88  ['is_processed' => 0],
89  ['is_processed != ?' => 0, 'store_id = ?' => $storeId]
90  );
91  $this->_eventManager->dispatch('catalogsearch_reset_search_result', ['store_id' => $storeId]);
92  return $this;
93  }
94 
102  public function getRelationsByChild($childIds)
103  {
104  $connection = $this->getConnection();
105  $linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
107  ->select()
108  ->from(
109  ['relation' => $this->getTable('catalog_product_relation')],
110  []
111  )->distinct(true)
112  ->join(
113  ['cpe' => $this->getTable('catalog_product_entity')],
114  'cpe.' . $linkField . ' = relation.parent_id',
115  ['cpe.entity_id']
116  )->where(
117  'relation.child_id IN (?)',
118  $childIds
119  );
120 
121  return $connection->fetchCol($select);
122  }
123 }
__construct(\Magento\Framework\Model\ResourceModel\Db\Context $context, \Magento\Framework\Event\ManagerInterface $eventManager, $connectionName=null, MetadataPool $metadataPool=null)
Definition: Fulltext.php:40
$connection
Definition: bulk.php:13