Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Magento: class to retrieve data from eav_attribute_option_value

Tags:

class

magento

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.

like image 667
Redox Avatar asked Feb 26 '12 20:02

Redox


2 Answers

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()
like image 86
LucScu Avatar answered Nov 02 '22 10:11

LucScu


// 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();
    }
}
like image 44
seanbreeden Avatar answered Nov 02 '22 12:11

seanbreeden