Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
BaseSelectAttributesSearchStrategy.php
Go to the documentation of this file.
1 <?php
8 
14 
26 {
30  private $resource;
31 
35  private $storeManager;
36 
40  private $scopeResolver;
41 
47  public function __construct(
48  ResourceConnection $resource,
49  StoreManagerInterface $storeManager,
50  IndexScopeResolver $scopeResolver
51  ) {
52  $this->resource = $resource;
53  $this->storeManager = $storeManager;
54  $this->scopeResolver = $scopeResolver;
55  }
56 
64  public function createBaseSelect(SelectContainer $selectContainer)
65  {
66  $select = $this->resource->getConnection()->select();
67  $mainTableAlias = $selectContainer->isFullTextSearchRequired() ? 'eav_index' : 'search_index';
68 
69  $select->distinct()
70  ->from(
71  [$mainTableAlias => $this->resource->getTableName('catalog_product_index_eav')],
72  ['entity_id' => 'entity_id']
73  )->where(
74  $this->resource->getConnection()->quoteInto(
75  sprintf('%s.store_id = ?', $mainTableAlias),
76  $this->storeManager->getStore()->getId()
77  )
78  );
79 
80  if ($selectContainer->isFullTextSearchRequired()) {
81  $tableName = $this->scopeResolver->resolve(
82  $selectContainer->getUsedIndex(),
83  $selectContainer->getDimensions()
84  );
85 
86  $select->joinInner(
87  ['search_index' => $tableName],
88  'eav_index.entity_id = search_index.entity_id',
89  []
90  )->joinInner(
91  ['cea' => $this->resource->getTableName('catalog_eav_attribute')],
92  'search_index.attribute_id = cea.attribute_id',
93  []
94  );
95  }
96 
97  $selectContainer = $selectContainer->updateSelect($select);
98  return $selectContainer;
99  }
100 }
$tableName
Definition: trigger.php:13
__construct(ResourceConnection $resource, StoreManagerInterface $storeManager, IndexScopeResolver $scopeResolver)
$storeManager
$resource
Definition: bulk.php:12