I have problem ,while i programmatically create product. I want add two different values for store views
$product = Mage::getModel('catalog/product');
$product->setStoreId(1)->setData('name', 'English name')->save();
$product->setStoreId(2)->setData('name', 'Polish name')->save();
After those operation I have proper data in catalog_product_entity_varchar
┌────────┬──────────────┬────────────┬────────┬─────────┬────────────┐
│value_id│entity_type_id│attribute_id│store_id│entity_id│value │
├────────┼──────────────┼────────────┼────────┼─────────┼────────────┤
│1 │10 │96 │0 │1 │English name│
├────────┼──────────────┼────────────┼────────┼─────────┼────────────┤
│6 │10 │96 │2 │1 │Polish name │
└────────┴──────────────┴────────────┴────────┴─────────┴────────────┘
And this data are good…..
BUT if I want add description (the same way) after name
$product->setStoreId(1)->setData('description', 'English')->save();
$product->setStoreId(2)->setData('description', 'Polish')->save();
catalog_product_entity_varchar
change to:
┌────────┬──────────────┬────────────┬────────┬─────────┬────────────┐
│value_id│entity_type_id│attribute_id│store_id│entity_id│value │
├────────┼──────────────┼────────────┼────────┼─────────┼────────────┤
│1 │10 │96 │0 │1 │English name│
├────────┼──────────────┼────────────┼────────┼─────────┼────────────┤
│2 │10 │96 │1 │1 │Polish name │
├────────┼──────────────┼────────────┼────────┼─────────┼────────────┤
│6 │10 │96 │2 │1 │Polish name │
└────────┴──────────────┴────────────┴────────┴─────────┴────────────┘
What is that? I must make additional operations between those setData? If I comment description part everything works well 🙁
Best Answer
The problem is that the second save uses the last setData called so basically you have the following situation.
You could either set the data at the same time:
Or you could do this by using an array of data:
Summary
Basically because there is no load/reset of the object in between the saves the data is always the same as the last save but with only the store id and what ever has been specifically changed by calling set data. The
setStoreId
does not load the store specific values is simply sets an id.