Skip to content

Commit

Permalink
Added Mage_Catalog_Model_Resource_Abstract::getAttributeRawText() met…
Browse files Browse the repository at this point in the history
…hod (#2312)
  • Loading branch information
justinbeaty authored Jul 26, 2022
1 parent e1741e5 commit 6eaea99
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions app/code/core/Mage/Catalog/Model/Resource/Abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,45 @@ public function getAttributeRawValue($entityId, $attribute, $store)
return $attributesData ? $attributesData : false;
}

/**
* Retrieve attribute's raw value from DB using its source model if available.
*
* @param int $entityId
* @param int|string|array $attribute atrribute's ids or codes
* @param int|Mage_Core_Model_Store $store
* @return bool|string|array
*/
public function getAttributeRawText($entityId, $attribute, $store)
{
if (!$entityId || empty($attribute)) {
return false;
}

if ($store instanceof Mage_Core_Model_Store) {
$store = $store->getId();
}

$store = (int)$store;
$attribute = is_array($attribute) ? $attribute : [$attribute];
$value = $this->getAttributeRawValue($entityId, $attribute, $store);

if (!$value) {
return false;
}

// Ensure we have an associative array of attribute => values
$values = is_array($value) ? $value : array_combine($attribute, [$value]);

foreach ($values as $_attribute => &$_value) {
$_attribute = (clone $this->getAttribute($_attribute))->setStoreId($store);
if ($_attribute->getSourceModel() || $_attribute->getFrontendInput() === 'select' || $_attribute->getFrontendInput() === 'multiselect') {
$_value = $_attribute->getSource()->getOptionText($_value);
}
}

return count($values) === 1 ? reset($values) : $values;
}

/**
* Reset firstly loaded attributes
*
Expand Down

0 comments on commit 6eaea99

Please sign in to comment.