Skip to content

Commit 9750462

Browse files
committed
ACP2E-2843: Products on the frontend use store specific data when Single-Store Mode is enabled
- solution with test coverage
1 parent 1639fb0 commit 9750462

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

app/code/Magento/Catalog/Model/ResourceModel/CatalogCategoryAndProductResolverOnSingleStoreMode.php

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,22 +52,22 @@ public function __construct(
5252
*/
5353
private function process(int $storeId, string $table): void
5454
{
55-
$productMetadata = $this->metadataPool->getMetadata(ProductInterface::class);
56-
$productLinkField = $productMetadata->getLinkField();
55+
$metadata = $this->metadataPool->getMetadata(ProductInterface::class);
56+
$linkField = $metadata->getLinkField();
5757
$catalogProductTable = $this->resourceConnection->getTableName($table);
5858

59-
$catalogProducts = $this->getCatalogProducts($table, $storeId);
60-
$rowIds = [];
59+
$catalogProducts = $this->getCatalogProducts($table, $linkField, $storeId);
60+
$linkFieldIds = [];
6161
$attributeIds = [];
6262
$valueIds = [];
6363
try {
6464
if ($catalogProducts) {
6565
foreach ($catalogProducts as $catalogProduct) {
66-
$rowIds[] = $catalogProduct[$productLinkField];
66+
$linkFieldIds[] = $catalogProduct[$linkField];
6767
$attributeIds[] = $catalogProduct[AttributeInterface::ATTRIBUTE_ID];
6868
$valueIds[] = $catalogProduct['value_id'];
6969
}
70-
$this->massDelete($catalogProductTable, $attributeIds, $rowIds);
70+
$this->massDelete($catalogProductTable, $linkField, $attributeIds, $linkFieldIds);
7171
$this->massUpdate($catalogProductTable, $valueIds);
7272
}
7373
} catch (LocalizedException $e) {
@@ -115,20 +115,21 @@ public function migrateCatalogCategoryAndProductTables(int $storeId): void
115115
* Delete default store related products
116116
*
117117
* @param string $catalogProductTable
118+
* @param string $linkField
118119
* @param array $attributeIds
119-
* @param array $rowIds
120+
* @param array $linkFieldIds
120121
* @return void
121122
*/
122-
private function massDelete(string $catalogProductTable, array $attributeIds, array $rowIds): void
123+
private function massDelete(string $catalogProductTable, string $linkField, array $attributeIds, array $linkFieldIds): void
123124
{
124125
$connection = $this->resourceConnection->getConnection();
125126

126127
$connection->delete(
127128
$catalogProductTable,
128129
[
129130
'store_id = ?' => Store::DEFAULT_STORE_ID,
130-
'attribute_id IN(?)' => $attributeIds,
131-
'row_id IN(?)' => $rowIds
131+
AttributeInterface::ATTRIBUTE_ID. ' IN(?)' => $attributeIds,
132+
$linkField.' IN(?)' => $linkFieldIds
132133
]
133134
);
134135
}
@@ -155,15 +156,16 @@ private function massUpdate(string $catalogProductTable, array $valueIds): void
155156
* Get list of products
156157
*
157158
* @param string $table
159+
* @param string $linkField
158160
* @param int $storeId
159161
* @return array
160162
*/
161-
private function getCatalogProducts(string $table, int $storeId): array
163+
private function getCatalogProducts(string $table, string $linkField, int $storeId): array
162164
{
163165
$connection = $this->resourceConnection->getConnection();
164166
$catalogProductTable = $this->resourceConnection->getTableName($table);
165167
$select = $connection->select()
166-
->from($catalogProductTable, ['value_id', 'attribute_id', 'row_id'])
168+
->from($catalogProductTable, ['value_id', AttributeInterface::ATTRIBUTE_ID, $linkField])
167169
->where('store_id = ?', $storeId);
168170
return $connection->fetchAll($select);
169171
}

0 commit comments

Comments
 (0)