I am trying to get Magento to set product attribute values on store views to be the same as the default values.
I have the following code called by an observer on
catalog_product_save_before
public function translateProduct($observer)
{
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
$product = Mage::getModel('catalog/product')->load($observer->getEvent()->getProduct()->getId());
foreach (Mage::app()->getWebsites() as $website) {
foreach ($website->getGroups() as $group) {
foreach ($group->getStores() as $store) {
$config = $store->getConfig('myconfig');
if($config['enabled']) {
foreach($product->getAttributes() as $attribute) {
if($attribute->getBackendType() == 'text' && $attribute->getFrontend()->getValue($product) != '') {
$product->setStoreId($store->getId())->setData($attribute->getAttributeCode(), $attribute->getFrontend()->getValue($product));
}
}
}
}
}
}
return $this;
}
I know my code and loops are being called as I did
echo 'Here'; die();
through the loop to test it.
Is this the correct way to set data for Magento products across multiple store views or have I gone wrong somewhere?
Thanks in advance for any help/tips/pointers 🙂
Whoa there fella.
You need only set your data at the default level. If an attribute value is not set for a store context it will be inferred from the default.
🙂