Create Magento attribute option multilingual programmatically -
i searching way create magento attribute options multilingual, more 1 language.
let's have store view name 'german' , 'english'. retrieve store language codes (the languages must set each on store view configuration pages):
$storelist = mage::app()->getstores(); $storelang = array(); foreach ($storelist $id => $s) { $storelang[$id] = substr(mage::getstoreconfig('general/locale/code', $id), 0, 2); }
this way create attribute options (the attributes exist already):
function addattributevalue($arg_attribute, $arg_value) { $attribute_model = mage::getmodel('eav/entity_attribute'); $attribute_code = $attribute_model->getidbycode('catalog_product', $arg_attribute); $attribute = $attribute_model->load($attribute_code); if (!attributevalueexists($arg_attribute, $arg_value)) { $value['option'] = array($arg_value, $arg_value); $result = array('value' => $value); $attribute->setdata('option', $result); $attribute->save(); echo "attribute '" . $arg_attribute . "' option '" . $arg_value . "' saved.<br />"; }
but 2nd language come play? right default value/default value gets filled database.
i prepare loop each language, not know right "switch" language.
when creating products, not attribute options, there method set product fields according language with
$product->setstoreid($lang_value);
but not sure on attribute options. can guys give me hint?
thanks.
problem solved. marius pointing out messed array. line wrong:
$value['option'] = array($arg_value, $arg_value);
set like:
$value['option'] = array($arg_value_label, $arg_value_lang1, $arg_value_lang2);
now able load the values each language , set them single line above. maybe not best solution, works me @ moment. have nice weekend everyone.
Comments
Post a Comment