I am running a method to save attribute store titles prgrammatically, but one attribute store title does not save when the method is run inside a loop. I thought it was a caching issue, but had no luck when I added the clear cache code like it says to do in this example code. This method runs properly and saves correctly when not run in a loop.
What am I missing?
I have also tried to put a sleep(1);
out of desperation without any luck.
The attribute store title is shown inside $model
after addData()
method.
$data = array();
$model = Mage::getModel('catalog/resource_eav_attribute');
$model->load($attr_id);
$data['frontend_label'] = $attribute_title; // array of titles for store views
$data['option'] = array('value' => $attribute_arr); // array of option labels for store views
$model->addData($data);
$model->save();
$session = Mage::getSingleton('adminhtml/session');
// Clear translation cache because attribute labels are stored in translation
Mage::app()->cleanCache(array(Mage_Core_Model_Translate::CACHE_TAG));
$session->setAttributeData(false);
e.g. of $data['frontend_label']
on the first loop:
[frontend_label] => Array (
[1] => Color2
[2] => Cõôlõôr
[3] => Còôlòôr
[0] => Color
)
On the next loop after the model saved once the attribute model is loaded again and Array[2]
was not been saved:
[frontend_label] => Array (
[1] => Color2
[2] => Color3
[3] => Còôlòôr
[0] => Color
)