We have right now three store views with different locales and plan to extend their quantity in a future.
We encountered issue when some attributes (price, name, etc) are properly received when we saving them with storeId = 0
, then, according to
app/code/core/Mage/Eav/Model/Entity/Abstract.php:992
the sql query like this is used to get these attributes:
SELECT `attr_table`.* FROM `catalog_product_entity_text` AS `attr_table`
INNER JOIN `eav_entity_attribute` AS `set_table`
ON attr_table.attribute_id = set_table.attribute_id AND set_table.attribute_set_id = '4'
WHERE (attr_table.entity_id = '50') AND (attr_table.store_id IN (0, 2))
As you can see, these is actually works for admin store if attr_table.store_id = 0
. But in some cases, like with setting default image for product (image
, small_image
and thumbnail
attributes) or using tag/tag
model it is impossible to use storeid = 0
.
So, the question is - how in this cases it is possible to update product attributes for all store ids at once without iterating over all store ids like this :
foreach ($stores as $store) {
Mage::app()->getStore()->setId($store);
$product = Mage::getModel('catalog/product')->load($product->getId());
$product->setStoreId($store);
$product->hasDataChanges(true);
Mage::getSingleton('catalog/product_action')
->updateAttributes(array($product->getEntityId()),
$attributes, $store);
}
and how if I have for example product with some $id
:
$product = Mage::getModel('catalog/product')->load($id);
$product->setName('newName')->save();
// how to save this model for all store views at once, without using setStoreId(0) ?
Thanks !