Skip to content

Commit 6228e94

Browse files
committed
MC-18696: The cart rules disappear with error: Item (Magento\SalesRule\Model\Rule\Interceptor) with the same ID "140" already exists
1 parent 90200f6 commit 6228e94

File tree

6 files changed

+145
-269
lines changed

6 files changed

+145
-269
lines changed

app/code/Magento/Rule/Model/ResourceModel/Rule/Collection/AbstractCollection.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,21 @@ public function addWebsiteFilter($websiteId)
8383
if ($website instanceof \Magento\Store\Model\Website) {
8484
$websiteIds[$index] = $website->getId();
8585
}
86+
$websiteIds[$index] = (int) $websiteIds[$index];
8687
}
88+
89+
$websiteSelect = $this->getConnection()->select();
90+
$websiteSelect->from(
91+
$this->getTable($entityInfo['associations_table']),
92+
[$entityInfo['rule_id_field']]
93+
)->distinct(
94+
true
95+
)->where(
96+
$this->getConnection()->quoteInto($entityInfo['entity_id_field'] . ' IN (?)', $websiteIds)
97+
);
8798
$this->getSelect()->join(
88-
['website' => $this->getTable($entityInfo['associations_table'])],
89-
$this->getConnection()->quoteInto('website.' . $entityInfo['entity_id_field'] . ' IN (?)', $websiteIds)
90-
. ' AND main_table.' . $entityInfo['rule_id_field'] . ' = website.' . $entityInfo['rule_id_field'],
99+
['website' => $websiteSelect],
100+
'main_table.' . $entityInfo['rule_id_field'] . ' = website.' . $entityInfo['rule_id_field'],
91101
[]
92102
);
93103
}

app/code/Magento/Rule/Test/Unit/Model/ResourceModel/Rule/Collection/AbstractCollectionTest.php

Lines changed: 0 additions & 200 deletions
This file was deleted.

0 commit comments

Comments
 (0)