Magento – How to Copy Category and Add to Another Category

categorymagento-1multistore

I have subcategory. I want move copy of it to another category. I do following

    $copy = clone $category;
    $copy->setId(null) // Remove the ID.
        ->save();
    $copy->move($parentCategory->getId());

This works, but new category have same name for each store. I have 5 stores with different languages. So category I want to copy have different name for each store.

Any ideas how to copy categories with different names for each store?

Edit:

Since I've accepted answer I've occurred issue – names weren't save correct for all stores. So I suggest use just

$copy = Mage::getModel('catalog/category');

instead

$copy = clone $category;
$copy->setId(null);

Best Answer

Try this, you have to assign the value different category name based on different store Id's

$allStores = Mage::app()->getStores();
$parentCategory = Mage::getModel('catalog/category')->load(5);
$parentCategoryId = $parentCategory->getId();
$category = Mage::getModel('catalog/category')->load(8); // The ID of the category you want to copy.
$copy = clone $category;
$copy->setId(null);
foreach ($allStores as $_eachStoreId => $val) 
{
        $storecategory = Mage::getModel('catalog/category')->setStoreId($_eachStoreId)->load(8);// The ID of the category you want to copy.
        $copy->setStoreId($_eachStoreId);
        $copy->setName($storecategory->getName());
        $copy->save();
}
$copy->move($parentCategoryId); 
Related Topic