CE 1.7.0.2 – How to Update Product Attributes for Multiple Store Views at Once

cece-1.7.0.2multistorestore-view

On a current project, we have one store view per country that the shop targets. Here's an example list of store views:

  • Switzerland (German)
  • Germany (German)
  • UK (English)
  • USA (English)
  • Australia (English)

All store views share one catalog, so the products are the same across all Store Views. Products are created in German initially. Now we need to add translations for some product attributes for the different languages, for example the product's descriptions need to be translated from German into English for the Store Views targeting English speaking countries.

The way that I have previously solved this (when there was just one Store View per language) was by opening each product in the Admin Panel and manually updating its description. But this is obviously too much work when there are multiple Store Views per language, because then I'd have to manually update the description once per Store View, using the same values for all English Store Views.

Is there a way of updating a product attribute's value for multiple Store Views at once? So that I can enter the product description in English just once, and it will be updated for all Store Views where the language is English?

I doubt that this can be solved using Magento Core so I'm open for suggestions using extensions or external tools.

Thanks!

Best Answer

If you wanted this as a feature you can write a module, and observe the save product event and loop through all the stores and either:

  • condition based looking for "english" if they are named like that
  • hardcode the id's
  • provide a configuration option in the admin to select the english stores.
  • add an attribute to the store object

Another way to do it as a one off:

<?php

require '../app/Mage.php';

$englishStore = 1; // English Store (the one you want to copy from)
$attribute = "short_description"; // Attribute to copy

foreach (Mage::app()->getWebsites() as $website) {
    foreach ($website->getGroups() as $group) {
        $stores = $group->getStores();
        foreach ($stores as $store) {
            //store object
            //print_r($store->getData());

            // if english found in name or change this so it's hardcoded store id's
            if (strstr($store->getData('name'),"english")) {

                $StoreToUpdateCollection = Mage::getModel('catalog/product')->getCollection()
                    ->addAttributeToSelect('*')
                    ->addAttributeToFilter('store_id', $store->getData('store_id'));

                foreach ($StoreToUpdateCollection as $product) {

                    // get the description from the base English store
                    $englishProduct = Mage::getModel('catalog/product')->setStoreId($englishStore)->loadByAttribute('sku', $product->getData('sku'));
                    $newValue = $englishProduct->getData($attribute);

                    // update the attributes for the current store for the product ID
                    Mage::getSingleton('catalog/product_action')->updateAttributes(
                        array($product->getData('id')),
                        array($attribute => $newValue),
                        $store->getData('store_id')
                    );
                }


            }


        }
    }
}

I have not tested the updating part, would suggest trying this on a dev version.