From e77908db630299bc63c60483681a51967db2fd3a Mon Sep 17 00:00:00 2001 From: beeplogic Date: Thu, 30 Jan 2014 01:12:58 -0800 Subject: [PATCH] Calling clear / removeAllItems / removeItemByKey does not remove model from protected _itemsById array --- .../Entity/Collection/AbstractCollection.php | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/app/code/Magento/Eav/Model/Entity/Collection/AbstractCollection.php b/app/code/Magento/Eav/Model/Entity/Collection/AbstractCollection.php index b8126a5d8cd8b..73f7fe0d73421 100644 --- a/app/code/Magento/Eav/Model/Entity/Collection/AbstractCollection.php +++ b/app/code/Magento/Eav/Model/Entity/Collection/AbstractCollection.php @@ -1533,4 +1533,38 @@ public function getLoadedIds() { return array_keys($this->_items); } + + /** + * Clear collection + * @return \Magento\Eav\Model\Entity\Collection\AbstractCollection + */ + public function clear() + { + $this->_itemsById = array(); + return parent::clear(); + } + + /** + * Remove all items from collection + * @return \Magento\Eav\Model\Entity\Collection\AbstractCollection + */ + public function removeAllItems() + { + $this->_itemsById = array(); + return parent::removeAllItems(); + } + + /** + * Remove item from collection by item key + * + * @param mixed $key + * @return \Magento\Eav\Model\Entity\Collection\AbstractCollection + */ + public function removeItemByKey($key) + { + if (isset($this->_items[$key])) { + unset($this->_itemsById[$this->_items[$key]->getId()]); + } + return parent::removeItemByKey($key); + } }