Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Page 1 of 12
Export & import categories
 
Luke Terry Creative Design
Jr. Member
 
Total Posts:  5
Joined:  2008-12-11
 

Hi everyone hoping I can get some help, how can I export categories from one magento store and import them in another? Thanks

EDIT: to be honest I am looking to export all categories, sub categories, products and product images from one magento site to another… is that possible?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Lakeshore Design Inc.
Jr. Member
 
Avatar
Total Posts:  1
Joined:  2008-07-22
 

Also looking for the same solution - perhaps SQL importing is the only method?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Luke Terry Creative Design
Jr. Member
 
Total Posts:  5
Joined:  2008-12-11
 

I was thinking that might be the only ansr, I’ve looked all aroudn the forum, found veriouse ways of moving images over but none worked for me… but as far as categories, products, images togeather had know luck… I am unsure that if I just made the categories again they would be the name categorie number that is in the CSV files exported??

 
Magento Community Magento Community
Magento Community
Magento Community
 
Nobby
Jr. Member
 
Total Posts:  22
Joined:  2008-06-23
 

I had a similar problem and the way i solved it was to create an export profile listing all the fields i needed using the import/export option from the system menu, I then imported it into my new database, you will need to manually copy the image files across from the media/import in your installation root directory.

 
Magento Community Magento Community
Magento Community
Magento Community
 
factfinder
Member
 
Avatar
Total Posts:  37
Joined:  2008-10-01
Pforzheim, Germany
 

To export category names or paths i wrote a small dataflow extension. By adding some xml tags to an advanced profile, you can add the categories to the product export. Unfortunately this module can’t import categories, but I hope it help anyway.

http://www.magentocommerce.com/extension/reviews/module/753/dataflow-extension

 
Magento Community Magento Community
Magento Community
Magento Community
 
pdxwebhead
Jr. Member
 
Total Posts:  27
Joined:  2008-07-16
Portland Oregon
 

Hey All,

I have been struggling with this issue of exporting categories for a few days. I am partially through solving it but, I have hit my limit in terms of programming skills.

I have managed to get the category tree out of my database using the SOAP Web Services interface using the following method.

**And I am fully aware that I may be doing this all backwards—that being said this is what I have managed to do..

First: I created a web services user in Admin -> Web Services -> Add new user
Second: I created a new Role for that user in Admin-> Web Servivces -> Roles and gave it full access to all services.
Third: I assigned that new role to the new user
My Webservices user is “soaper” and the key or password is also “soaper”

Next I created a script by cobbling together some code fragments I found in the API services page and some other code floating around online.

It looks like this:

<?php

    $proxy 
= new SoapClient('http://127.0.0.1:8888/magento/index.php/api/?wsdl');
    
$sessionId $proxy->login('soaper''soaper');
    
$result $allCategories $proxy->call($sessionId'category.tree');
    
    echo 
'<pre>';
    
print_r($result);
    echo 
'<pre>';
?>

I saved this code as a PHP file called “get_categories.php” and dropped it in the root folder for my Magento installation.  Then to call it, I simply pointed my browser to the file—something like this: http://yourmagentohost/get_categories.php

And boom, it spits out what looks like the xml schema for the category tree with all of your categories and related goodness.

Array
(
[category_id] => 1
[parent_id] => 0
[name] => Root Catalog
[position] => 2
[level] => 0
[children] => Array
(
[0] => Array
(
[category_id] => 2
[parent_id] => 1
[name] => Default Category
[is_active] => 1
[position] => 2
[level] => 1
[children] => Array
(
[0] => Array
(
[category_id] => 6
[parent_id] => 2
[name] => Mens
[is_active] => 1
[position] => 3
[level] => 2
[children] => Array
(
[0] => Array
(
[category_id] => 7
[parent_id] => 6
[name] => Outerwear
[is_active] => 1
[position] => 2
[level] => 3
[children] => Array
(

My question is this; can anyone help extend this code so it’s flattened and can be read by Excel?

 
Magento Community Magento Community
Magento Community
Magento Community
 
vidhulac
Member
 
Avatar
Total Posts:  33
Joined:  2009-01-06
Bangalore
 

i have imported all my catogories at a time without using the product import profile.

1. Create an advanced profile called “Import Categories”.
2. put the xml :

<action type="dataflow/convert_adapter_io" method="load">
    <var 
name="type">file</var>
    <var 
name="path">var/import</var>
    <var 
name="filename"><![CDATA[Categories.csv]]></var>
    <var 
name="format"><![CDATA[csv]]></var>
</
action>
<
action type="dataflow/convert_parser_csv" method="parse">
    <var 
name="delimiter"><![CDATA[,]]></var>
    <var 
name="enclose"><![CDATA["]]></var>
    <var name="
fieldnames">true</var>
    <var name="
store"><![CDATA[0]]></var>
    <var name="
number_of_records">1</var>
    <var name="
decimal_separator"><![CDATA[.]]></var>
    <var name="
adapter">catalog/convert_adapter_category</var>
    <var name="
method">parse</var>
</action>

3. click save to save the profile

 
Magento Community Magento Community
Magento Community
Magento Community
 
vidhulac
Member
 
Avatar
Total Posts:  33
Joined:  2009-01-06
Bangalore
 

1. add the model to over ride the local folder.

<models>
            <
catalog>
                <
rewrite>
                    <
convert_adapter_category>Mycomp_Catalog_Model_Convert_Adapter_Category</convert_adapter_category>
                </
rewrite>
            </
catalog>
        </
models>

2. Put this code in the file in app/code/local/mycomp/Catelog/Model/Convert/Adapter/Category.php

class Mycomp_Catalog_Model_Convert_Adapter_Category
    
extends Mage_Eav_Model_Convert_Adapter_Entity
{
    
protected $_categoryCache = array();

    protected 
$_stores;

    
/**
     * Category display modes
     */
    
protected $_displayModes = array( 'PRODUCTS''PAGE''PRODUCTS_AND_PAGE');

    public function 
parse()
    
{
        $batchModel 
Mage::getSingleton('dataflow/batch');
        
/* @var $batchModel Mage_Dataflow_Model_Batch */

        
$batchImportModel $batchModel->getBatchImportModel();
        
$importIds $batchImportModel->getIdCollection();

        foreach (
$importIds as $importId{
            
//print '<pre>'.memory_get_usage().'</pre>';
            
$batchImportModel->load($importId);
            
$importData $batchImportModel->getBatchData();

            
$this->saveRow($importData);
        
}
    }

    
/**
     * Save category (import)
     *
     * @param array $importData
     * @throws Mage_Core_Exception
     * @return bool
     */
    
public function saveRow(array $importData)
    
{
        
if (empty($importData['store'])) {
            
if (!is_null($this->getBatchParams('store'))) {
                $store 
$this->getStoreById($this->getBatchParams('store'));
            
else {
                $message 
Mage::helper('catalog')->__('Skip import row, required field "%s" not defined''store');
                
Mage::throwException($message);
            
}
        } 
else {
            $store 
$this->getStoreByCode($importData['store']);
        
}

        
if ($store === false{
            $message 
Mage::helper('catalog')->__('Skip import row, store "%s" field not exists'$importData['store']);
            
Mage::throwException($message);
        
}

        $rootId 
$store->getRootCategoryId();
        if (!
$rootId{
            
return array();
        
}
        $rootPath 
'1/'.$rootId;
        if (empty(
$this->_categoryCache[$store->getId()])) {
            $collection 
Mage::getModel('catalog/category')->getCollection()
                ->
setStore($store)
                ->
addAttributeToSelect('name');
            
$collection->getSelect()->where("path like '".$rootPath."/%'");

            foreach (
$collection as $cat{
                $pathArr 
explode('/'$cat->getPath());
                
$namePath '';
                for (
$i=2$l=sizeof($pathArr); $i<$l$i++) {
                    $name 
$collection->getItemById($pathArr[$i])->getName();
                    
$namePath .= (empty($namePath) ? '' '/').trim($name);
                
}
                $cat
->setNamePath($namePath);
            
}

            $cache 
= array();
            foreach (
$collection as $cat{
                $cache[strtolower
($cat->getNamePath())$cat;
                
$cat->unsNamePath();
            
}
            $this
->_categoryCache[$store->getId()$cache;
        
}
        $cache 
=& $this->_categoryCache[$store->getId()];

        
$importData['categories'preg_replace('#\s*/\s*#''/'trim($importData['categories']));
        if (!empty(
$cache[$importData['categories']])) {
            
return true;
        
}

        $path 
$rootPath;
        
$namePath '';

        
$i 1;
        
$categories explode('/'$importData['categories']);
        foreach (
$categories as $catName{
            $namePath 
.= (empty($namePath) ? '' '/').strtolower($catName);
            if (empty(
$cache[$namePath])) {

                $dispMode 
$this->_displayModes[2];

                
$cat Mage::getModel('catalog/category')
                    ->
setStoreId($store->getId())
                    ->
setPath($path)
                    ->
setName($catName)
                    ->
setIsActive(1)
                    ->
setIsAnchor(1)
                    ->
setDisplayMode($dispMode)
                    ->
save();
                
$cache[$namePath] $cat;
            
}
            $catId 
$cache[$namePath]->getId();
            
$path .= '/'.$catId;
            
$i++;
        
}

        
return true;
    
}

    
/**
     * Retrieve store object by code
     *
     * @param string $store
     * @return Mage_Core_Model_Store
     */
    
public function getStoreByCode($store)
    
{
        $this
->_initStores();
        if (isset(
$this->_stores[$store])) {
            
return $this->_stores[$store];
        
}
        
return false;
    
}

    
/**
     *  Init stores
     *
     *  @param    none
     *  @return      void
     */
    
protected function _initStores ()
    
{
        
if (is_null($this->_stores)) {
            $this
->_stores Mage::app()->getStores(truetrue);
            foreach (
$this->_stores as $code => $store{
                $this
->_storesIdCode[$store->getId()$code;
            
}
        }
    }
}

?>

4. Put all the categories in the csv format under : var/import/Categories.csv.
the format is :

"store","categories"
"default"
,"Apparel/Shoes"
"default"
,"Apparel/Clearance"
"default"
,"Electronics"

3. Run the profile “Import Categories”

 
Magento Community Magento Community
Magento Community
Magento Community
 
Paulus
Guru
 
Total Posts:  335
Joined:  2008-07-21
 

Thanks sanThosh, I’ll give it shot next couple days

 
Magento Community Magento Community
Magento Community
Magento Community
 
Paulus
Guru
 
Total Posts:  335
Joined:  2008-07-21
 

Hi,

You write:
1. add the model to over ride the local folder.

Can you tell me where to add this?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Paulus
Guru
 
Total Posts:  335
Joined:  2008-07-21
 

Also this path
app/code/local/mycomp/Catelog/Model/Convert/Adapter/Category.php
does not seem to go further than this on my end
app/code/local/

Any advise?

 
Magento Community Magento Community
Magento Community
Magento Community
 
vidhulac
Member
 
Avatar
Total Posts:  33
Joined:  2009-01-06
Bangalore
 

the model is under

local/mycomp/catalog/etc/config.xml

where “mycomp” can be any value according to your project.

 
Magento Community Magento Community
Magento Community
Magento Community
 
vidhulac
Member
 
Avatar
Total Posts:  33
Joined:  2009-01-06
Bangalore
 
Paulus - 04 March 2009 05:06 AM

Also this path
app/code/local/mycomp/Catelog/Model/Convert/Adapter/Category.php
does not seem to go further than this on my end
app/code/local/

Any advise?

please check this url to get the solution.

overriding a model or block

 
Magento Community Magento Community
Magento Community
Magento Community
 
Paulus
Guru
 
Total Posts:  335
Joined:  2008-07-21
 

Okay, just to be 110% sure, i have to create the entire path local/mycomp/catalog/etc/config.xml as this is not in my version 1.2.1.2

Thanks for the prompt reply by the way.

 
Magento Community Magento Community
Magento Community
Magento Community
 
nafnaf1000
Sr. Member
 
Total Posts:  209
Joined:  2008-02-21
 

I get this error??/

Declared adapter catalog/convert_adapter_category not found

Any ideas?

 
Magento Community Magento Community
Magento Community
Magento Community
 
vidhulac
Member
 
Avatar
Total Posts:  33
Joined:  2009-01-06
Bangalore
 
nafnaf1000 - 05 March 2009 09:27 AM

I get this error??/


Declared adapter catalog/convert_adapter_category not found

Any ideas?

please check this url to get the solution.

overriding a model or block

“Mycomp” is just an example. you can use your own name.

1. First make an xml file in app\etc\modules
2. create your folder in app\code\local
3. override the adapter model in Catalog\etc\config.xml inside your folder in local.
4. put the category page in Catalog\Model\Convert\Adapter\Category.php

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top
Page 1 of 12