0

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);
2

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); 
  • i have updated the code... – saravanavelu Jan 29 '16 at 12:34

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.