52 $this->_resourceHelper = $resourceHelper;
62 $this->
_init(
'catalog_product_index_eav',
'entity_id');
74 [
'ca' => $this->
getTable(
'catalog_eav_attribute')],
77 [
'ea' => $this->
getTable(
'eav_attribute')],
78 'ca.attribute_id = ea.attribute_id',
84 if ($multiSelect ==
true) {
85 $select->where(
'ea.backend_type = ?',
'varchar')->where(
'ea.frontend_input = ?',
'multiselect');
87 $select->where(
'ea.backend_type = ?',
'int')->where(
'ea.frontend_input = ?',
'select');
102 $this->_prepareSelectIndex($entityIds, $attributeId);
116 protected function _prepareSelectIndex($entityIds =
null, $attributeId =
null)
125 $productIdField = $this->
getMetadataPool()->getMetadata(ProductInterface::class)->getLinkField();
126 $attrIdsFlat = implode(
',', array_map(
'intval', $attrIds));
127 $ifNullSql =
$connection->getIfNullSql(
'pis.value',
'COALESCE(ds.value, dd.value)');
134 [
'dd' => $this->
getTable(
'catalog_product_entity_int')],
138 [
'ds' => $this->
getTable(
'catalog_product_entity_int')],
139 "ds.store_id = s.store_id AND ds.attribute_id = dd.attribute_id AND " .
140 "ds.{$productIdField} = dd.{$productIdField}",
143 [
'd2d' => $this->
getTable(
'catalog_product_entity_int')],
145 "d2d.store_id = 0 AND d2d.{$productIdField} = dd.{$productIdField} AND d2d.attribute_id = %s",
150 [
'd2s' => $this->
getTable(
'catalog_product_entity_int')],
151 "d2s.store_id = s.store_id AND d2s.attribute_id = d2d.attribute_id AND " .
152 "d2s.{$productIdField} = d2d.{$productIdField}",
155 [
'cpe' => $this->
getTable(
'catalog_product_entity')],
156 "cpe.{$productIdField} = dd.{$productIdField}",
159 [
'pis' => $this->
getTable(
'catalog_product_entity_int')],
160 "pis.{$productIdField} = cpe.{$productIdField} " .
161 "AND pis.attribute_id = dd.attribute_id AND pis.store_id = s.store_id",
166 '(ds.value IS NOT NULL OR dd.value IS NOT NULL)' 168 (
new \
Zend_Db_Expr(
'COALESCE(d2s.value, d2d.value)')) .
' = ' . ProductStatus::STATUS_ENABLED
170 "dd.attribute_id IN({$attrIdsFlat})" 172 'NOT(pis.value IS NULL AND pis.value_id IS NOT NULL)' 174 $ifNullSql .
' IS NOT NULL' 180 'value' =>
new \
Zend_Db_Expr(
'COALESCE(ds.value, dd.value)'),
185 if ($entityIds !==
null) {
186 $ids = implode(
',', array_map(
'intval', $entityIds));
187 $select->where(
"cpe.entity_id IN({$ids})");
193 $this->_eventManager->dispatch(
194 'prepare_catalog_product_index_select',
224 $productIdField = $this->
getMetadataPool()->getMetadata(ProductInterface::class)->getLinkField();
229 $this->
getTable(
'eav_attribute_option'),
230 [
'attribute_id',
'option_id']
231 )->where(
'attribute_id IN(?)', $attrIds);
238 $productValueExpression =
$connection->getCheckSql(
'pvs.value_id > 0',
'pvs.value',
'pvd.value');
240 [
'pvd' => $this->
getTable(
'catalog_product_entity_varchar')],
247 [
'pvs' => $this->
getTable(
'catalog_product_entity_varchar')],
248 "pvs.{$productIdField} = pvd.{$productIdField} AND pvs.attribute_id = pvd.attribute_id" 249 .
' AND pvs.store_id=cs.store_id',
252 [
'cpe' => $this->
getTable(
'catalog_product_entity')],
253 "cpe.{$productIdField} = pvd.{$productIdField}",
262 'pvd.attribute_id IN(?)',
265 'cpe.entity_id IS NOT NULL' 268 'entity_id' =>
'cpe.entity_id',
269 'attribute_id' =>
'attribute_id',
270 'store_id' =>
'cs.store_id',
271 'value' => $productValueExpression,
272 'source_id' =>
'cpe.entity_id',
276 $statusCond =
$connection->quoteInto(
'=?', ProductStatus::STATUS_ENABLED);
279 if ($entityIds !==
null) {
280 $select->where(
'cpe.entity_id IN(?)', $entityIds);
285 $this->_eventManager->dispatch(
286 'prepare_catalog_product_index_select',
314 [
'entity_id',
'attribute_id',
'store_id',
'value',
'source_id'],
329 return $this->tableStrategy->getTableName(
'catalog_product_index_eav');
344 foreach (
$values as $valueId) {
348 if (
$i % 10000 == 0) {
370 if (!$this->tableStrategy->getUseIdxTable()) {
372 $connection->createTemporaryTableLike($additionalIdxTable, $idxTable);
390 $connection->dropTemporaryTable($additionalIdxTable);
_prepareIndex($entityIds=null, $attributeId=null)
_getIndexableAttributes($multiSelect)
_addAttributeToSelect($select, $attrCode, $entity, $store, $condition=null, $required=false)
__construct(\Magento\Framework\Model\ResourceModel\Db\Context $context, \Magento\Framework\Indexer\Table\StrategyInterface $tableStrategy, \Magento\Eav\Model\Config $eavConfig, \Magento\Framework\Event\ManagerInterface $eventManager, \Magento\Catalog\Model\ResourceModel\Helper $resourceHelper, $connectionName=null)
_init($mainTable, $idFieldName)
_prepareMultiselectIndex($entityIds=null, $attributeId=null)
_prepareRelationIndex($parentIds=null)
_prepareRelationIndexSelect(array $parentIds=null)
_saveIndexData(array $data)
_getIndexableAttributesCondition()