diff --git a/app/code/core/Mage/Eav/Model/Config.php b/app/code/core/Mage/Eav/Model/Config.php index d73ac825f8a..4b3d1e3710c 100644 --- a/app/code/core/Mage/Eav/Model/Config.php +++ b/app/code/core/Mage/Eav/Model/Config.php @@ -209,7 +209,7 @@ protected function _loadEntityTypes() protected function _loadEntityAttributes($entityType, $storeId) { // preload attributes in array form to avoid instantiating models for every attribute even if it is never accessed - $entityAttributes = $entityType->getAttributeCollection() + $entityAttributes = $entityType->newAttributeCollection() ->addStoreLabel($storeId) ->getData(); @@ -221,7 +221,7 @@ protected function _loadEntityAttributes($entityType, $storeId) $attributeId = $entityAttributeData['attribute_id']; $attributeCode = $entityAttributeData['attribute_code']; - // workaround for getAttributeCollection()->getData() returning all columns as string + // workaround for newAttributeCollection()->getData() returning all columns as string foreach (self::NUMERIC_ATTRIBUTE_COLUMNS as $key) { if (!isset($entityAttributeData[$key])) { continue; diff --git a/app/code/core/Mage/Eav/Model/Entity/Type.php b/app/code/core/Mage/Eav/Model/Entity/Type.php index 582b77189d7..20eee9fd100 100644 --- a/app/code/core/Mage/Eav/Model/Entity/Type.php +++ b/app/code/core/Mage/Eav/Model/Entity/Type.php @@ -99,24 +99,41 @@ public function loadByCode($code) /** * Retrieve entity type attributes collection * - * @param int $setId - * @return Mage_Eav_Model_Resource_Entity_Attribute_Collection + * @param int|null $setId + * @return Mage_Eav_Model_Resource_Entity_Attribute_Collection */ public function getAttributeCollection($setId = null) { + if ($setId === null && $this->_attributes !== null) { + return $this->_attributes; + } elseif (isset($this->_attributesBySet[$setId])) { + return $this->_attributesBySet[$setId]; + } + + $collection = $this->newAttributeCollection($setId); + if ($setId === null) { - if ($this->_attributes === null) { - $this->_attributes = $this->_getAttributeCollection() - ->setEntityTypeFilter($this); - } - $collection = $this->_attributes; + $this->_attributes = $collection; } else { - if (!isset($this->_attributesBySet[$setId])) { - $this->_attributesBySet[$setId] = $this->_getAttributeCollection() - ->setEntityTypeFilter($this) - ->setAttributeSetFilter($setId); - } - $collection = $this->_attributesBySet[$setId]; + $this->_attributesBySet[$setId] = $collection; + } + + return $collection; + } + + /** + * Create entity type attributes collection + * + * @param int|null $setId + * @return Mage_Eav_Model_Resource_Entity_Attribute_Collection + */ + public function newAttributeCollection($setId = null) + { + $collection = $this->_getAttributeCollection() + ->setEntityTypeFilter($this); + + if ($setId !== null) { + $collection->setAttributeSetFilter($setId); } return $collection;