Skip to content

Commit

Permalink
Fixed array_keys(null) and call to undefined method in `Mage_Eav_Mo…
Browse files Browse the repository at this point in the history
…del_Config` (#4036)

Co-authored-by: Sven Reichel <[email protected]>
  • Loading branch information
F1Red5 and sreichel authored Jun 29, 2024
1 parent a7a1bd6 commit 1d4fe88
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 23 deletions.
49 changes: 32 additions & 17 deletions app/code/core/Mage/Eav/Model/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ public function setCurrentStoreId($storeId)
$this->_currentStoreId = $storeId;
}

/**
* @throws Mage_Core_Model_Store_Exception
*/
protected function _storeId()
{
if (isset($this->_currentStoreId) && $this->_currentStoreId !== false) {
Expand All @@ -134,6 +137,9 @@ protected function _storeId()
return Mage::app()->getStore()->getId();
}

/**
* @throws Exception
*/
protected function _initializeStore($storeId = null)
{
if ($storeId === null) {
Expand Down Expand Up @@ -176,7 +182,6 @@ protected function _initializeStore($storeId = null)
}

/**
* @param $storeId
* @return void
* @throws Exception
*/
Expand Down Expand Up @@ -216,7 +221,8 @@ 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
// preload attributes in array form to avoid instantiating
// models for every attribute even if it is never accessed
$entityAttributes = $entityType->newAttributeCollection()
->addStoreLabel($storeId)
->getData();
Expand Down Expand Up @@ -346,6 +352,7 @@ protected function _isCacheEnabled()
*
* @param array $attributeData
* @return Mage_Eav_Model_Entity_Attribute_Abstract|false
* @throws Mage_Core_Exception
*/
protected function _hydrateAttribute($attributeData)
{
Expand All @@ -361,7 +368,9 @@ protected function _hydrateAttribute($attributeData)
$attribute->setData($attributeData);

$entity = $entityType->getEntity();
if (in_array($attribute->getAttributeCode(), $entity->getDefaultAttributes())) {
if (method_exists($entity, 'getDefaultAttributes')
&& in_array($attribute->getAttributeCode(), $entity->getDefaultAttributes())
) {
$attribute
->setBackendType(Mage_Eav_Model_Entity_Attribute_Abstract::TYPE_STATIC)
->setIsGlobal(1);
Expand All @@ -378,10 +387,10 @@ protected function _hydrateAttribute($attributeData)
* Get entity type object by entity type code/identifier
*
* @param mixed $code
* @param string|null $code
* @param string $field
* @param string|null $field
* @return Mage_Eav_Model_Entity_Type
* @throws Mage_Core_Exception
* @throws Exception
*/
public function getEntityType($code, $field = null)
{
Expand Down Expand Up @@ -438,16 +447,16 @@ protected function _getDefaultAttributeIfExists($entityType, $attributeCode, $st
}

$entity = $entityType->getEntity();
if (method_exists($entity, 'getDefaultAttributes')) {
if (in_array($attributeCode, $entity->getDefaultAttributes())) {
$attributeData = [
'entity_type_id' => $entityType->getId(),
'attribute_code' => $attributeCode,
];
$attribute = $this->_hydrateAttribute($attributeData);
$this->_defaultAttributes[$storeId][$entityType->getId()][$attributeCode] = $attribute;
return $attribute;
}
if (method_exists($entity, 'getDefaultAttributes')
&& in_array($attributeCode, $entity->getDefaultAttributes())
) {
$attributeData = [
'entity_type_id' => $entityType->getId(),
'attribute_code' => $attributeCode,
];
$attribute = $this->_hydrateAttribute($attributeData);
$this->_defaultAttributes[$storeId][$entityType->getId()][$attributeCode] = $attribute;
return $attribute;
}

// cache a miss as well
Expand All @@ -462,6 +471,8 @@ protected function _getDefaultAttributeIfExists($entityType, $attributeCode, $st
* @param mixed $code
* @param int|null $storeId
* @return Mage_Eav_Model_Entity_Attribute_Abstract|false
* @throws Mage_Core_Exception
* @throws Exception
*/
public function getAttribute($entityType, $code, $storeId = null)
{
Expand Down Expand Up @@ -503,6 +514,7 @@ public function getAttribute($entityType, $code, $storeId = null)
/**
* @param mixed $entityType
* @return Mage_Eav_Model_Entity_Attribute_Abstract[]
* @throws Mage_Core_Exception
*/
public function getAttributes($entityType)
{
Expand All @@ -527,6 +539,8 @@ public function getAttributes($entityType)
* @param Mage_Eav_Model_Entity_Type $entityType
* @param Varien_Object $object
* @return array
* @throws Mage_Core_Exception
* @throws Exception
*/
public function getEntityAttributeCodes($entityType, $object = null)
{
Expand All @@ -549,7 +563,8 @@ public function getEntityAttributeCodes($entityType, $object = null)
$attributeCodes = [];
foreach ($attributeIds as $attributeId) {
$attribute = $this->getAttribute($entityType, $attributeId, $storeId);
// need to verify attribute actually exists to avoid problems with deleted attributes that left behind some remnants
// need to verify attribute actually exists to avoid problems
// with deleted attributes that left behind some remnants
if ($attribute) {
$attributeCodes[] = $attribute->getAttributeCode();
}
Expand All @@ -563,7 +578,6 @@ public function getEntityAttributeCodes($entityType, $object = null)
/**
* @param int|int[] $attributeSetId
* @return int[]
* @throws Mage_Core_Model_Store_Exception
*/
public function getAttributeSetAttributeIds($attributeSetId)
{
Expand All @@ -588,6 +602,7 @@ public function getAttributeSetAttributeIds($attributeSetId)
* @param mixed $entityType
* @param string $attribute
* @return Mage_Eav_Model_Entity_Attribute_Abstract|null
* @throws Mage_Core_Exception
* @deprecated Equivalent to getAttribute(...), use getAttribute(...) instead
* Get attribute object for collection usage
*
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Eav/Model/Entity/Attribute/Abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
* @method bool getIsConfigurable()
* @method bool getIsFilterable()
* @method bool getIsFilterableInSearch()
* @method bool setIsGlobal()
* @method $this setIsGlobal(int $value)
* @method bool getIsRequired()
* @method bool getIsSearchable()
* @method bool getIsUnique()
Expand Down
5 changes: 0 additions & 5 deletions phpstan.dist.baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -3010,11 +3010,6 @@ parameters:
count: 1
path: app/code/core/Mage/Eav/Model/Attribute/Data/File.php

-
message: "#^Call to an undefined method Mage_Core_Model_Resource_Abstract\\:\\:getDefaultAttributes\\(\\)\\.$#"
count: 1
path: app/code/core/Mage/Eav/Model/Config.php

-
message: "#^Method Mage_Eav_Model_Config\\:\\:getAttribute\\(\\) should return Mage_Eav_Model_Entity_Attribute_Abstract\\|false but returns Mage_Eav_Model_Entity_Attribute_Interface\\.$#"
count: 1
Expand Down

0 comments on commit 1d4fe88

Please sign in to comment.