Had to investigate a weird bug in our product data, turns out to be a Magento core "feature" that can cause option id/label collisions when using getOptionId()
of Mage_Eav_Model_Entity_Attribute_Source_Abstract
.
Truncated getAllOptions()
array for a common size attribute:
Array
(
[232] => Array
(
[value] => 104
[label] => 44
)
[331] => Array
(
[value] => 405
[label] => 104
)
)
Mage_Eav_Model_Entity_Attribute_Source_Abstract::getOptionId()
implementation in 1.9.2.4:
public function getOptionId($value)
{
foreach ($this->getAllOptions() as $option) {
if (strcasecmp($option['label'], $value)==0 || $option['value'] == $value) {
return $option['value'];
}
}
return null;
}
Fetch option id for labels 44
and 104
:
$a = Mage::getModel('eav/entity_attribute')->load(<attribute_id>);
$optionId = $a->getSource()->getOptionId("44");
$optionId = $a->getSource()->getOptionId("104");
Both calls will return 104
as id for the option label, should be 405
for the second call.
Patch below, in theory this might break existing code, but probably safe to apply in practice.