copy categories from other categories in same magento
-
01-10-2020 - |
Pregunta
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.
Solución
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>";
}
?>
Licenciado bajo: CC-BY-SA con atribución
No afiliado a magento.stackexchange