Skip to content

Commit 0b918af

Browse files
committed
MAGETWO-65245: parent_id of deleted configurable product variation does not get sent to ElasticSearch
1 parent 4a1d4fe commit 0b918af

File tree

2 files changed

+41
-52
lines changed

2 files changed

+41
-52
lines changed

app/code/Magento/CatalogSearch/Model/Indexer/Fulltext.php

Lines changed: 1 addition & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,16 @@
55
*/
66
namespace Magento\CatalogSearch\Model\Indexer;
77

8-
use Magento\Catalog\Api\Data\ProductInterface;
98
use Magento\CatalogSearch\Model\Indexer\Fulltext\Action\FullFactory;
109
use Magento\CatalogSearch\Model\Indexer\Scope\State;
1110
use Magento\CatalogSearch\Model\ResourceModel\Fulltext as FulltextResource;
1211
use Magento\Framework\App\ObjectManager;
13-
use Magento\Framework\EntityManager\MetadataPool;
1412
use Magento\Framework\Search\Request\Config as SearchRequestConfig;
1513
use Magento\Framework\Search\Request\DimensionFactory;
1614
use Magento\Store\Model\StoreManagerInterface;
1715

1816
/**
1917
* Provide functionality for Fulltext Search indexing.
20-
*
21-
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2218
*/
2319
class Fulltext implements \Magento\Framework\Indexer\ActionInterface, \Magento\Framework\Mview\ActionInterface
2420
{
@@ -72,13 +68,6 @@ class Fulltext implements \Magento\Framework\Indexer\ActionInterface, \Magento\F
7268
*/
7369
private $indexScopeState;
7470

75-
/**
76-
* Holder for MetadataPool instance.
77-
*
78-
* @var MetadataPool
79-
*/
80-
private $metadataPool = null;
81-
8271
/**
8372
* @param FullFactory $fullActionFactory
8473
* @param IndexerHandlerFactory $indexerHandlerFactory
@@ -133,37 +122,12 @@ public function execute($ids)
133122
]);
134123
foreach ($storeIds as $storeId) {
135124
$dimension = $this->dimensionFactory->create(['name' => 'scope', 'value' => $storeId]);
136-
$productIds = array_unique(array_merge($ids, $this->getRelationsByChild($ids)));
125+
$productIds = array_unique(array_merge($ids, $this->fulltextResource->getRelationsByChild($ids)));
137126
$saveHandler->deleteIndex([$dimension], new \ArrayObject($productIds));
138127
$saveHandler->saveIndex([$dimension], $this->fullAction->rebuildStoreIndex($storeId, $ids));
139128
}
140129
}
141130

142-
/**
143-
* Retrieve product relations by children.
144-
*
145-
* @param int|array $childIds
146-
* @return array
147-
*/
148-
private function getRelationsByChild($childIds)
149-
{
150-
$connection = $this->fulltextResource->getConnection();
151-
$linkField = $this->getMetadataPool()->getMetadata(ProductInterface::class)->getLinkField();
152-
$select = $connection->select()->from(
153-
['relation' => $this->fulltextResource->getTable('catalog_product_relation')],
154-
[]
155-
)->join(
156-
['cpe' => $this->fulltextResource->getTable('catalog_product_entity')],
157-
'cpe.' . $linkField . ' = relation.parent_id',
158-
['cpe.entity_id']
159-
)->where(
160-
'relation.child_id IN (?)',
161-
$childIds
162-
)->distinct(true);
163-
164-
return $connection->fetchCol($select);
165-
}
166-
167131
/**
168132
* Execute full indexation
169133
*
@@ -211,18 +175,4 @@ public function executeRow($id)
211175
{
212176
$this->execute([$id]);
213177
}
214-
215-
/**
216-
* Get Metadata Pool instance.
217-
*
218-
* @return MetadataPool
219-
*/
220-
private function getMetadataPool()
221-
{
222-
if ($this->metadataPool === null) {
223-
$this->metadataPool = ObjectManager::getInstance()->get(MetadataPool::class);
224-
}
225-
226-
return $this->metadataPool;
227-
}
228178
}

app/code/Magento/CatalogSearch/Model/ResourceModel/Fulltext.php

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
*/
66
namespace Magento\CatalogSearch\Model\ResourceModel;
77

8+
use Magento\Catalog\Api\Data\ProductInterface;
9+
use Magento\Framework\App\ObjectManager;
10+
use Magento\Framework\EntityManager\MetadataPool;
11+
812
/**
913
* CatalogSearch Fulltext Index resource model
1014
*/
@@ -17,17 +21,27 @@ class Fulltext extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
1721
*/
1822
protected $_eventManager;
1923

24+
/**
25+
* Holder for MetadataPool instance.
26+
*
27+
* @var MetadataPool
28+
*/
29+
private $metadataPool;
30+
2031
/**
2132
* @param \Magento\Framework\Model\ResourceModel\Db\Context $context
2233
* @param \Magento\Framework\Event\ManagerInterface $eventManager
2334
* @param string $connectionName
35+
* @param MetadataPool $metadataPool
2436
*/
2537
public function __construct(
2638
\Magento\Framework\Model\ResourceModel\Db\Context $context,
2739
\Magento\Framework\Event\ManagerInterface $eventManager,
28-
$connectionName = null
40+
$connectionName = null,
41+
MetadataPool $metadataPool = null
2942
) {
3043
$this->_eventManager = $eventManager;
44+
$this->metadataPool = $metadataPool ? : ObjectManager::getInstance()->get(MetadataPool::class);
3145
parent::__construct($context, $connectionName);
3246
}
3347

@@ -53,4 +67,29 @@ public function resetSearchResults()
5367
$this->_eventManager->dispatch('catalogsearch_reset_search_result');
5468
return $this;
5569
}
70+
71+
/**
72+
* Retrieve product relations by children.
73+
*
74+
* @param int|array $childIds
75+
* @return array
76+
*/
77+
public function getRelationsByChild($childIds)
78+
{
79+
$connection = $this->getConnection();
80+
$linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
81+
$select = $connection->select()->from(
82+
['relation' => $this->getTable('catalog_product_relation')],
83+
[]
84+
)->join(
85+
['cpe' => $this->getTable('catalog_product_entity')],
86+
'cpe.' . $linkField . ' = relation.parent_id',
87+
['cpe.entity_id']
88+
)->where(
89+
'relation.child_id IN (?)',
90+
$childIds
91+
)->distinct(true);
92+
93+
return $connection->fetchCol($select);
94+
}
5695
}

0 commit comments

Comments
 (0)