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

Export & import categories
 
pezomatic
Sr. Member
 
Avatar
Total Posts:  190
Joined:  2008-11-05
 

I do not think the script imports/creates categories, I think it only allows you to assign categories that already exist in your Magento database to the products that you are importing.

 
Magento Community Magento Community
Magento Community
Magento Community
 
rentown
Jr. Member
 
Total Posts:  29
Joined:  2009-03-01
 

so if assign the product to the right category.

i can import all products to the right category right?

so if i can already import all my categories with the script form this tread.

i can import all product to the categories that i have imported.

so i can combine this thread to upload my categories

and the “Import category structure with products using DataFlow”

to import my products.

is that correct?

thanks

 
Magento Community Magento Community
Magento Community
Magento Community
 
pezomatic
Sr. Member
 
Avatar
Total Posts:  190
Joined:  2008-11-05
 

Let me do a clean install of magento so I can try to see how this script works. It’s been over a year since I last experimented with Magento so I am not sure how much help I can be to you at the moment.

 
Magento Community Magento Community
Magento Community
Magento Community
 
rentown
Jr. Member
 
Total Posts:  29
Joined:  2009-03-01
 
pezomatic - 07 November 2009 05:16 PM

Let me do a clean install of magento so I can try to see how this script works. It’s been over a year since I last experimented with Magento so I am not sure how much help I can be to you at the moment.

thank you,

i really appreciated

 
Magento Community Magento Community
Magento Community
Magento Community
 
a1454
Jr. Member
 
Total Posts:  2
Joined:  2009-07-29
 
pezomatic - 07 November 2009 05:16 PM

Let me do a clean install of magento so I can try to see how this script works. It’s been over a year since I last experimented with Magento so I am not sure how much help I can be to you at the moment.

Mind if I ask what eCommerce are you using right now if you are not using Magento?

I originally choose Magento because it offers most of the features I need, then I found out its lacking of support and documentation, and even if you pay for the Enterprise Edition, you are basically paying $10k+ a year for a few extra feature, all the problems Community version have is still there.

I was determined I’m going to figure out Magento, so I bought a few books on PHP and cracked through all of them in one week(skipping all my sleep), just to find out there is still a lot more to learn and its just not something I can achieve in a short time…

I’m getting to the point where I’m considering alternatives.

 
Magento Community Magento Community
Magento Community
Magento Community
 
a1454
Jr. Member
 
Total Posts:  2
Joined:  2009-07-29
 

Okay, after 3 days of sleep deprivation and 5 packs of cigarette,

Finally got Hocke’s method working for me.

I was getting an error saying the store does not exist, and the problem was actually very simple. Inside the categories.csv file, the field store name actually refers to the CODENAME of your STOREVIEW.

So in my case my store view is called English, I put that in there exactly, it still didn’t work, almost drove me insane, then I found out the store view’s name is “English” but its code is “english” without the capital letter. So tried that, works perfectly…

Now I’m gonna get busy importing 2000+ categories and then come back to figure out how to import product with category information....

 
Magento Community Magento Community
Magento Community
Magento Community
 
osol
Member
 
Avatar
Total Posts:  35
Joined:  2009-11-10
 

Can anybody help me to extend santhosh’s module to import category images also?

 
Magento Community Magento Community
Magento Community
Magento Community
 
osol
Member
 
Avatar
Total Posts:  35
Joined:  2009-11-10
 

I have sorted it out myself .Below is the code which i hope will help some one

Three things to take care before running this

1.Add the extra field “categoryImage” to set image names.
2.Save images to import in media/import folder
3.Make sure media/catalog/category folder exists

<?php
class ImpCat_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++;
        
}
        
//Code block added for image
        
$file preg_replace('#\s*/\s*#''/'trim($importData['categoryImage']));
        
$sourceFilePath Mage::getBaseDir('media') . DS 'import' DS $file;
        
$targetFileName $cache[$namePath]->getId().'-'.$file;
        if(
file_exists($sourceFilePath) && !is_dir($sourceFilePath))
        
{
            copy
($sourceFilePath,Mage::getBaseDir('media') . DS 'catalog'.DS.'category' DS $targetFileName);
            
$cache[$namePath]->setImage($targetFileName)
                            ->
save(); 
        
}
        
//Code block added for image ends here

        
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;
            
}
        }
    }
}

?>
 
Magento Community Magento Community
Magento Community
Magento Community
 
Watercooling
Jr. Member
 
Total Posts:  28
Joined:  2008-07-24
 

For anyone whos planning to use the script from the wiki above ( http://www.magentocommerce.com/wiki/how-to/how_to_import_category_structure_with_products_using_dataflow )
please be aware of a little error for anyone who patches the files by their own:

Line 35:  foreach (explode(’ , ‘, $categories) as $categoryPathStr) {

The delimiter “,” has two whitespaces arround so if you want to use multiple categories you need “categorie1 , categorie2 , categorie3”. Anyway i changed the delimiter to : which is in most cases better. “categorie1:categorie2:categorie3”

 
Magento Community Magento Community
Magento Community
Magento Community
 
quatermain
Jr. Member
 
Total Posts:  9
Joined:  2008-09-15
 

Hello, I have this error:

<br /> <b>Fatal error</b>: Call to undefined method Mycomp_Catalog_Model_Convert_Adapter_Category::getStoreById() in <b>/home6/umelecke/public_html/test/app/code/local/Mycomp/Catalog/Model/Convert/Adapter/Category.php</b> on line <b>43</b><br />

This show me with MyComp solution and ImpCat_Katalogdaten_importieren solution although I do all things in “manual”. Can you help me?

 
Magento Community Magento Community
Magento Community
Magento Community
 
toinus
Jr. Member
 
Total Posts:  27
Joined:  2009-04-09
 

Could someone post the import script using char | and not / to explode the cat|subcats ?
Because with this configuration it interferes with / in my cat names.
Furthermore, how could I get the accentued letter working ?

Regards,
Antoine

 
Magento Community Magento Community
Magento Community
Magento Community
 
lesya
Jr. Member
 
Total Posts:  23
Joined:  2009-05-25
 
Luke Terry Creative Design - 15 December 2008 02:43 PM

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?

Hi

One of the effective ways to do this is use migration service. <a href="http://www.shopping-cart-migration.com/shopping-cart-migration-options/223-magento-to-magento-migration">Cart2Cart</a> online service can help you. It supports export of all the data you mentioned between magento sites. Hope it helps you.

 
Magento Community Magento Community
Magento Community
Magento Community
 
ilib
Member
 
Total Posts:  49
Joined:  2008-11-25
Москва
 
John Carlson - 03 September 2009 05:38 AM

Hey guys,

John Here! they guy with the import/export custom options, tier prices, grouped products (associated products)..

I’m currently working on a category import/export module based somewhat on the code from this post and from my own experience with the other module.

I’ve got the export to work just fine.. accept that it doesn’t give me the store ID and I don’t have it exporting the image file path/names yet.
The import works with hierarchy using faux_id’s for initial import of categories, but doesn’t import image files for the category.

I’m looking for 2 people with sites that have many categories to test it.

email me: johncarlson21@gmail.com to give me your info, and I will send you the files and an example import file.

John

Hi John. I wonder if your great work is ready? And if it works with magento 1.4.0.0 ?
I modified PHP code of santhosh kumar so that I could add descriptions, IsActive and IsAnchor to imported file (see attachment) but it does not work on the latest release of Magento 1.4.0.0beta1. The descriptions are not shown up until you click on each category and save it via admin interface, while IsActive and IsAnchor are imported correctly.

The fields of CSV file I used:
store,categories,IsActive,IsAnchor,description

File Attachments
Category.php  (File Size: 5KB - Downloads: 355)
 
Magento Community Magento Community
Magento Community
Magento Community
 
ilib
Member
 
Total Posts:  49
Joined:  2008-11-25
Москва
 

now it works in v1.4.0.0betta1. The descriptions are being recorded when that piece of code inside Categories.php is modified like this:

$path = $rootPath;
$namePath = ‘’;

$i = 1;
$categories = explode(’/’, $importData[’categories’]);
$IsActive = $importData[’IsActive’];
$IsAnchor = $importData[’IsAnchor’];
$description = trim($importData[’description’]);

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($IsActive)
->setIsAnchor($IsAnchor)
->setDescription($description)
->setDisplayMode($dispMode)
->save();
*/
$cat = Mage::getModel(’catalog/category’);
$cat->setStoreId($store->getId());
$general[’name’] = $catName;
$general[’path’] = $path;
$general[’description’] = $description;
$general[’landing_page’] = “”;
$general[’display_mode’] = $dispMode;
$general[’is_active’] = $IsActive;
$general[’is_anchor’] = $IsAnchor;
$cat->addData($general);
$cat->save();

$cat = Mage::getModel(’catalog/category’)->load($cat->getId());
$cat->setDescription($description . ‘ xxx’);
$cat->save();

# echo “Success! Id: “.$cat->getId().” “.$catName;

$cache[$namePath] = $cat;
//var_dump($cat);
}
$catId = $cache[$namePath]->getId();
$path .= ‘/’.$catId;
$i++;
}

But the truth is I have no idea why it did not work with the file in my previous post. Any ideas?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Template fans
Guru
 
Total Posts:  446
Joined:  2009-11-02
 

I tried. But it didn’t work.

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top