Skip to content

Commit 7b74ece

Browse files
author
Oleksandr Iegorov
committed
MC-42811: Missing Bundled Products on Category Pages
1 parent 70d1517 commit 7b74ece

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

app/code/Magento/Bundle/Model/Plugin/Frontend/ProductIdentitiesExtender.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function afterGetIdentities(CatalogProduct $product, array $identities):
6363
private function getChildrenIds($entityId): array
6464
{
6565
if (!isset($this->cacheChildrenIds[$entityId])) {
66-
$this->cacheChildrenIds[$entityId] = $this->type->getChildrenIds($entityId);
66+
$this->cacheChildrenIds[$entityId] = $this->type->getChildrenIds($entityId, false);
6767
}
6868

6969
return $this->cacheChildrenIds[$entityId];

app/code/Magento/Elasticsearch/Model/Indexer/IndexerHandler.php

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
namespace Magento\Elasticsearch\Model\Indexer;
77

8+
use Magento\Catalog\Model\Category;
89
use Magento\CatalogSearch\Model\Indexer\Fulltext;
910
use Magento\Elasticsearch\Model\Adapter\Elasticsearch as ElasticsearchAdapter;
1011
use Magento\Elasticsearch\Model\Adapter\Index\IndexNameResolver;
@@ -15,6 +16,7 @@
1516
use Magento\Framework\Indexer\SaveHandler\Batch;
1617
use Magento\Framework\Indexer\SaveHandler\IndexerInterface;
1718
use Magento\Framework\Search\Request\Dimension;
19+
use Magento\Framework\Indexer\CacheContext;
1820

1921
/**
2022
* Indexer Handler for Elasticsearch engine.
@@ -73,6 +75,11 @@ class IndexerHandler implements IndexerInterface
7375
*/
7476
private const DEPLOYMENT_CONFIG_INDEXER_BATCHES = 'indexer/batch_size/';
7577

78+
/**
79+
* @var CacheContext
80+
*/
81+
private $cacheContext;
82+
7683
/**
7784
* IndexerHandler constructor.
7885
* @param IndexStructureInterface $indexStructure
@@ -83,6 +90,7 @@ class IndexerHandler implements IndexerInterface
8390
* @param array $data
8491
* @param int $batchSize
8592
* @param DeploymentConfig|null $deploymentConfig
93+
* @param CacheContext|null $cacheContext
8694
*/
8795
public function __construct(
8896
IndexStructureInterface $indexStructure,
@@ -91,8 +99,9 @@ public function __construct(
9199
Batch $batch,
92100
ScopeResolverInterface $scopeResolver,
93101
array $data = [],
94-
$batchSize = self::DEFAULT_BATCH_SIZE,
95-
?DeploymentConfig $deploymentConfig = null
102+
int $batchSize = self::DEFAULT_BATCH_SIZE,
103+
?DeploymentConfig $deploymentConfig = null,
104+
?CacheContext $cacheContext = null
96105
) {
97106
$this->indexStructure = $indexStructure;
98107
$this->adapter = $adapter;
@@ -102,6 +111,7 @@ public function __construct(
102111
$this->batchSize = $batchSize;
103112
$this->scopeResolver = $scopeResolver;
104113
$this->deploymentConfig = $deploymentConfig ?: ObjectManager::getInstance()->get(DeploymentConfig::class);
114+
$this->cacheContext = $cacheContext ?: ObjectManager::getInstance()->get(CacheContext::class);
105115
}
106116

107117
/**
@@ -119,11 +129,30 @@ public function saveIndex($dimensions, \Traversable $documents)
119129
foreach ($this->batch->getItems($documents, $this->batchSize) as $documentsBatch) {
120130
$docs = $this->adapter->prepareDocsPerStore($documentsBatch, $scopeId);
121131
$this->adapter->addDocs($docs, $scopeId, $this->getIndexerId());
132+
$this->updateCacheContext($docs);
122133
}
123134
$this->adapter->updateAlias($scopeId, $this->getIndexerId());
124135
return $this;
125136
}
126137

138+
/**
139+
* Add category cache tags for the affected products to the cache context
140+
*
141+
* @param array $docs
142+
* @return void
143+
*/
144+
private function updateCacheContext(array $docs) : void
145+
{
146+
$categoryIds = [];
147+
foreach ($docs as $document) {
148+
array_push($categoryIds, ...$document['category_ids']);
149+
}
150+
if (!empty($categoryIds)) {
151+
$categoryIds = array_unique($categoryIds);
152+
$this->cacheContext->registerEntities(Category::CACHE_TAG, $categoryIds);
153+
}
154+
}
155+
127156
/**
128157
* @inheritdoc
129158
*/

0 commit comments

Comments
 (0)