0

I want to change some data of all categories (all store views).

This is my code:

$category = Mage::getModel('catalog/category');
$tree = $category->getTreeModel();
$tree->load();
$ids = $tree->getCollection()->getAllIds();
asort($ids);
$categories = array();
if($ids) {
    foreach ( $ids as $id ) {
        $cat = $category->load($id);
        if($cat->getId()) {
            $cat->setName($cat->getName().' add some text');
            $cat->save();
        }
    }
}

Unfortunately I get only the data of the second language. I need to change data of all languages (store views).

Does anyone has an idea?

2
$storeIds = Mage::getModel('core/store')->getCollection()->getAllIds();
$category = Mage::getModel('catalog/category');
$tree = $category->getTreeModel();
$tree->load();
$ids = $tree->getCollection()->getAllIds();
asort($ids);
$categories = array();
if($ids) {
    foreach ( $ids as $id ) {
        foreach ($storeIds as $storeId) {
            if ($storeId == 0) {
                continue;
            }
            $cat = $category->setStoreId($storeId)->load($id);
            if($cat->getId()) {
                $cat->setName($cat->getName().' add some text');
                $cat->save();
            }
        }
    }
}
| improve this answer | |
  • $cat = $category->setStoreId($storeId)->load($id); that's nice tip, the only way I found to get categories translation from collection. – electroid Nov 21 '16 at 8:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.