I am trying to copy my categories from the old site to the new one it's on different domains but it shares the same hosting server that's why i use the real path.
i already know how to get the categories and how to add them.
the problem here is that i declare the Mage class from domain and get the categories with this code:
$mageFilename = '/chroot/home/stagingv/staging.vatrin.com/html/app/Mage.php';
include($mageFilename);
Mage::init();
Mage::app()->setCurrentStore(1);
$_helper = Mage::helper('catalog/category');
$_categories = $_helper->getStoreCategories();
but when i'm trying to call the Mage class from the new domain with this code in the same page to add the categories to the new domain:
$mageFilename = '/chroot/home/stagingv/gostorestaging.vatrin.com/html/app/Mage.php';
include($mageFilename);
Mage::init();
it return this error:
Fatal error: Cannot redeclare class Mage in /chroot/home/stagingv/gostorestaging.vatrin.com/html/app/Mage.php on line 61
of course i can't use the first one when adding it will add the new categories on the old domain and i don't need that. how i can solve it or any better solution i appreciate?
UPDATE
This is my code:
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
//header('Content-type: text/plain; charset=utf-8');
error_reporting(E_ALL);
$mageFilename = '/chroot/home/stagingv/staging.vatrin.com/html/app/Mage.php';
include($mageFilename);
Mage::app()->setCurrentStore(1);
// this what get all categories
getListOfCats();
$mageFilename = '/chroot/home/stagingv/gostorestaging.vatrin.com/html/app/Mage.php';
include($mageFilename);
Mage::app();
// this what get all categories after changing the mage file.
getListOfCats();
function getListOfCats() {
$_helper = Mage::helper('catalog/category');
$_categories = $_helper->getStoreCategories();
$currentCategory = Mage::registry('current_category');
$listCats = array();
$model = Mage::getModel('catalog/category');
if (count($_categories) > 0) {
foreach($_categories as $_category) {
$listCatsTemp = array();
$listCatsTemp['id'] = $_category->getId();
$listCatsTemp['name'] = $_category->getName();
$listCatsTemp['child'] = array();
$_category = $model->load($_category->getId());
$_subcategories = $_category->getChildrenCategories();
if (count($_subcategories) > 0) {
$listSubCats = array();
foreach($_subcategories as $_subcategory) {
$listSubCatsTemp = array();
$listSubCatsTemp['id'] = $_subcategory->getId();
$listSubCatsTemp['name'] = $_subcategory->getName();
$listSubCatsTemp['child'] = array();
$_category1 = $model->load($_subcategory->getId());
$_subcategories1 = $_category1->getChildrenCategories();
if (count($_subcategories1) > 0) {
$listSubSubCat1 = array();
foreach($_subcategories1 as $_subcategory1) {
$listSubSubCatTemp = array();
$listSubSubCatTemp['id'] = $_subcategory1->getId();
$listSubSubCatTemp['name'] = $_subcategory1->getName();
$listSubSubCatTemp['child'] = array();
$_category2 = $model->load($_subcategory1->getId());
$_subcategories2 = $_category2->getChildrenCategories();
if (count($_subcategories2) > 0) {
$listSubSubCat2 = array();
foreach($_subcategories2 as $_subcategory2) {
$listSubSubCatTemp1 = array();
$listSubSubCatTemp1['id'] = $_subcategory2->getId();
$listSubSubCatTemp1['name'] = $_subcategory2->getName();
$listSubSubCatTemp1['child'] = array();
$_category3 = $model->load($_subcategory2->getId());
$_subcategories3 = $_category3->getChildrenCategories();
if (count($_subcategories3) > 0) {
$listSubSubCat3 = array();
foreach($_subcategories3 as $_subcategory3) {
$listSubSubCatTemp2 = array();
$listSubSubCatTemp2['id'] = $_subcategory3->getId();
$listSubSubCatTemp2['name'] = $_subcategory3->getName();
$listSubSubCat3[] = $listSubSubCatTemp2;
} // end foreach sub cat 2
$listSubSubCatTemp1['child'] = $listSubSubCat3;
} else {
$listSubSubCat3 = array();
} // end if sub cat 2
$listSubSubCat2[] = $listSubSubCatTemp1;
} // end foreach sub cat 2
} else {
$listSubSubCat2 = array();
} // end if sub cat 2
$listSubSubCatTemp['child'] = $listSubSubCat2;
$listSubSubCat1[] = $listSubSubCatTemp;
} // end foreach sub cat 1
} else {
$listSubSubCat1 = array();
} // end if sub cat 1
$listSubCatsTemp['child'] = $listSubSubCat1;
$listSubCats[] = $listSubCatsTemp;
} // end foreach sub cat
} else {
$listSubCats = array();
} // end if sub cat
$listCatsTemp['child'] = $listSubCats;
$listCats[] = $listCatsTemp;
} // end foreach cats
} // end if cats
echo '<hr>';
echo '<pre>';
print_r($listCats);
echo '</pre>';
}
?>
Thanks in Advance.