Skip to content

Instantly share code, notes, and snippets.

@AurelienLavorel
Created June 19, 2020 15:58
Show Gist options
  • Save AurelienLavorel/493e367581b24ed1eb9d88b30c7140e4 to your computer and use it in GitHub Desktop.
Save AurelienLavorel/493e367581b24ed1eb9d88b30c7140e4 to your computer and use it in GitHub Desktop.
Avoid duplicate id
diff --git a/vendor/magento/framework/Data/AbstractSearchResult.php b/vendor/magento/framework/Data/AbstractSearchResult.php
index 05c8e39f524658b559ad7d3df37d598c443c12ef..f28c42cd2751caa14716efffe5a757f9988200f7 100644
--- a/vendor/magento/framework/Data/AbstractSearchResult.php
+++ b/vendor/magento/framework/Data/AbstractSearchResult.php
@@ -265,11 +265,6 @@ abstract class AbstractSearchResult extends AbstractDataObject implements Search
{
$itemId = $this->getItemId($item);
if ($itemId !== null) {
- if (isset($this->data['items'][$itemId])) {
- throw new \Exception(
- 'Item (' . get_class($item) . ') with the same ID "' . $item->getId() . '" already exists.'
- );
- }
$this->data['items'][$itemId] = $item;
} else {
$this->data['items'][] = $item;
diff --git a/vendor/magento/framework/Data/Collection.php b/vendor/magento/framework/Data/Collection.php
index 8514d82f6aa7189f5802205db5a9de59b2e8777a..6b982da1dce5c49f63c8985ece121c17399f5c3c 100644
--- a/vendor/magento/framework/Data/Collection.php
+++ b/vendor/magento/framework/Data/Collection.php
@@ -402,12 +402,6 @@ class Collection implements \IteratorAggregate, \Countable, ArrayInterface, Coll
$itemId = $this->_getItemId($item);
if ($itemId !== null) {
- if (isset($this->_items[$itemId])) {
- //phpcs:ignore Magento2.Exceptions.DirectThrow
- throw new \Exception(
- 'Item (' . get_class($item) . ') with the same ID "' . $item->getId() . '" already exists.'
- );
- }
$this->_items[$itemId] = $item;
} else {
$this->_addItem($item);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment