Redox
Redox

Reputation: 993

Magento: class to retrieve data from eav_attribute_option_value

I have the following data in eav_attribute_option_value of a Magento 1.4.0.1 installation.

value_id  |  option_id  |  store_id  |  value
-------------------------------------------------------------------------
35        |  7          |  0         |  Levertijd 1 tot 3 werkdagen
36        |  6          |  0         |  Levertijd 4 tot 10 werkdagen
37        |  5          |  0         |  Langer dan 11 werkdagen
38        |  4          |  0         |  Levertijd onbekend
39        |  3          |  0         |  Pre-Order

I have the data of option_id in a var, say $delivery (example = 6). I want to retrieve the data by using a existing class of Magento. So output data should be "Levertijd 4 tot 10 werkdagen".

Does anyone know if there is an existing function in Magento that I can use for this?

Thanks in advance.

Upvotes: 5

Views: 4000

Answers (2)

LucScu
LucScu

Reputation: 359

You can directly load attribute_option_value entity with $option_id

$eav_attribute_option_value = Mage::getModel('eav/entity_attribute_option')
    ->getCollection()
    ->setStoreFilter()
    ->join('attribute', 'attribute.attribute_id=main_table.attribute_id', 'attribute_code')
    ->addFieldToFilter('main_table.option_id', array('eq' => $option_id))
    ->getFirstItem();

Then access to its value

$eav_attribute_option_value->getValue()

Upvotes: 6

seanbreeden
seanbreeden

Reputation: 6097

// Your variable
$option_id = 6;

// Retrieve values
$attributes = Mage::getModel('eav/entity_attribute_option')->getCollection()->setStoreFilter()->join('attribute','attribute.attribute_id=main_table.attribute_id', 'attribute_code');
foreach ($attributes as $attribute) {
    if ($attribute->getOptionId()==$option_id) {
        echo $attribute->getValue();
    }
}

Upvotes: 3

Related Questions