0

I try to translate my options label for an attribute using installer.

I try this code :

$attributeId = Mage::getResourceModel('eav/entity_attribute')->getIdByCode('catalog_product', 'my_attribute'); // return the good value
$attribute = Mage::getModel('catalog/resource_eav_attribute')->load($attributeId);

$_product = Mage::getModel('catalog/product');
$attr = $_product->getResource()->getAttribute("my_attribute");
if ($attr->usesSource()) {
    $optionId = $attr->getSource()->getOptionId("option_to_translate"); // return the good value
    $options = Mage::getResourceModel('eav/entity_attribute_option_collection')->setIdFilter($optionId);
    $orderId = $options->getData()[0]['sort_order']; // return the good value
}

$attribute->setData('option', array(
    'value'=> array($optionId => array (
        0 => 'option_to_translate',
        1 => 'first_trad',
        2 => 'second_trad',
        3 => 'and so on',
        )),
    'order' => array($optionId => $orderId)
    )
);
$attribute->save();

This code, in my installer, not work : in my option, the value 'option_to_translate' is replaced by empty value, for the others stores no value is add, but the order value still be there.

Curiously, this code works if I'm not in my installer.. Someone knows why ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.