4

I want to copy categories with sub categories and add it to another categories with same mangento with different stores.

For Example:

Store One Category
      Category 1
         Sub Category 1
         Sub Category 2
      Category 2
         Sub Category 1
         Sub Category 2

Store Two Category

Now from this I want to add all Categories of Store One Category to Store Two Category without any extention.

3
  • Personally i am using extension for that and it works perfectly for me. Commented Aug 4, 2016 at 11:43
  • if you don't want an extension how do you expect to do it?
    – Marius
    Commented Aug 4, 2016 at 11:43
  • It can be possible using code ? Commented Aug 4, 2016 at 11:50

1 Answer 1

3

Here, I got solve for this question.

<?php
    require_once 'app/Mage.php';
    Mage::app();
    $categories  = Mage::getModel('catalog/category')->load('id')->getChildrenCategories(); //here id of category which you want to copy categories.

    $parentCategory = Mage::getModel('catalog/category')->load('id'); //here id of category which you want to paste categories.
    foreach ($categories as $category) 
    {
        echo $category->getId()."<br>";
        $collection = $category->getProductCollection();
        $category = Mage::getModel('catalog/category')->load($category->getId());

        $copy = clone $category;
        $copy->setPath($parentCategory->getPath());
        $copy->getProductCollection($prodCollection);
        $copy->setId(null) 
         ->save();

        foreach ($collection as $product) 
        {
           $product->getId();
           $cate = $product->getCategoryIds();
           $cate[] = $parentCategory->getId();
           $cate[] = $copy->getId();
           $product->setCategoryIds($cate);
           $product->save();
        }
        echo $copy->getId()."<br>";
    }
?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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