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 2 of 12
Export & import categories
 
nafnaf1000
Sr. Member
 
Total Posts:  209
Joined:  2008-02-21
 

Starting profile execution, please wait…
Warning: Please don’t close window during importing/exporting data
Starting Mage_Dataflow_Model_Convert_Adapter_Io :: load
Loaded successfully: “/home/monkeysc/domains/lyselectronics.com/public_html/var/import/Categories.csv”
Starting Mage_Dataflow_Model_Convert_Parser_Csv :: parse
Declared adapter catalog/convert_adapter_category not found
Finished profile execution.

 
Magento Community Magento Community
Magento Community
Magento Community
 
vidhulac
Member
 
Avatar
Total Posts:  33
Joined:  2009-01-06
Bangalore
 
nafnaf1000 - 06 March 2009 08:11 AM

Starting profile execution, please wait…
Warning: Please don’t close window during importing/exporting data
Starting Mage_Dataflow_Model_Convert_Adapter_Io :: load
Loaded successfully: “/home/monkeysc/domains/lyselectronics.com/public_html/var/import/Categories.csv”
Starting Mage_Dataflow_Model_Convert_Parser_Csv :: parse
Declared adapter catalog/convert_adapter_category not found
Finished profile execution.

can you explain me the complete steps taken by you. i think you might have missed some file or some step in between.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Marlboro51
Jr. Member
 
Total Posts:  4
Joined:  2008-11-17
 

Hi , thanks for this help.
I obtain the same error as NafNaf1000.
I think there is a mistake with xml files.
if i well understood, here is what i’ve done (i called my module ImpCat as Import Categories):
1 - I created this file :
app/etc/modules/ImpCat_Module.xml

<?xml version="1.0"?>
<config>
  <
modules>
    <
ImpCat_Module>
      <
codePool>local</codePool>
      <
active>true</active>
    </
ImpCat_Module>
  </
modules>
</
config>
2 - i created the local subfolder and this xml file :
app/code/local/ImpCat/Catalog/etc/config.xml
<?xml version="1.0"?>
<config>
  <global>
    <
models>
      <
catalog>
        <
rewrite>
            <
convert_adapter_category>ImpCat_Catalog_Model_Convert_Adapter_Category</convert_adapter_category>
        </
rewrite>
      </
catalog>
    </
models>
  </global>
</
config>

then the php code in app/code/local/ImpCat/Catalog/Model/Convert/Adapter/Category.php

class ImpCat_Catalog_Model_Convert_Adapter_Category
(...)

I created the advanced import under magento admin with your XML details.

And then, whan i ran my profile i get these :

Démarrage de l'exécution du profil, veuillez patienter...
    * Attention : ne fermez pas cette fenêtre pendant l'
import/export de données

    
Starting Mage_Dataflow_Model_Convert_Adapter_Io :: load
    
Loaded successfully"/home/magento/magento/var/import/Categories.csv"
    
Starting Mage_Dataflow_Model_Convert_Parser_Csv :: parse
    
Declared adapter catalog/convert_adapter_category not found
    
Exécution du profil terminée.

Any Idea ? I think there is a problem with the declaration of the module between catalog and ImpCat but something is missing to me…

Thanks for your help
Olivier

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

1. instead of app/etc/modules/ImpCat_Module.xml

write as app/etc/modules/ImpCat_All.xml

2. instead of

<?xml version="1.0"?>
<config>
  <
modules>
    <
ImpCat_Module>
      <
codePool>local</codePool>
      <
active>true</active>
    </
ImpCat_Module>
  </
modules>
</
config>

write

<?xml version="1.0"?>
<config>
  <
modules>
    <
ImpCat_Catalog>
      <
codePool>local</codePool>
      <
active>true</active>
    </
ImpCat_Catalog>
  </
modules>
</
config>

don’t forget to extend the class “Mage_Eav_Model_Convert_Adapter_Entity”

class ImpCat_Catalog_Model_Convert_Adapter_Category
    
extends Mage_Eav_Model_Convert_Adapter_Entity
 
Magento Community Magento Community
Magento Community
Magento Community
 
Marlboro51
Jr. Member
 
Total Posts:  4
Joined:  2008-11-17
 

Thanks for your answer.
All works fine .... I’am importing my 1729 categories…
Hope this message will helps others peoples…
Olivier

 
Magento Community Magento Community
Magento Community
Magento Community
 
Marlboro51
Jr. Member
 
Total Posts:  4
Joined:  2008-11-17
 
pdxwebhead - 13 February 2009 09:01 PM

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

Hi pdxwebhead,
if you still searching for an answer about your post, try 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');

function 
get_cat($cat)
{
        $sep 
';';
        
$cols str_repeat($sep,$cat['level']+1);
        
printf("\"%s\"%s\"%s\"\n",$cat['category_id'],$cols,$cat['name']);
        foreach (
$cat['children'as $child)
        
{
                get_cat
($child);
        
}
}
    
echo '<pre>';
//    print_r($result);
    
get_cat($result);
    echo 
'<pre>';
?>

then copy and paste in a csv file....
Olivier

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

Okay, i just tested it and it works for me too, v1.2.1.2.
Thanks!

ps. Will it just skip unchanged, existing categories that are in the csv file?

 
Magento Community Magento Community
Magento Community
Magento Community
 
wokka
Member
 
Total Posts:  45
Joined:  2008-06-06
 

I’m running version 1.2.1 and getting this error when running the import:-

* Starting profile execution, please wait…
* Warning: Please do close window during importing/exporting data

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 ‘

‘.memory_get_usage().’

* ‘; $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(true, true); foreach ($this->_stores as $code => $store) { $this->_storesIdCode[$store->getId()] = $code; } } } } ?> Starting Mage_Dataflow_Model_Convert_Adapter_Io :: load
* Loaded successfully: “/var/www/vhosts/cartridgeoffers.co.uk/httpdocs/var/import/Categories.csv”
* Starting Mage_Dataflow_Model_Convert_Parser_Csv :: parse
* Method “parse” not defined in adapter catalog/convert_adapter_category
* Finished profile execution.

I think I’ve followed all the instructions.... can anyone help, please?
John

 
Magento Community Magento Community
Magento Community
Magento Community
 
Marlboro51
Jr. Member
 
Total Posts:  4
Joined:  2008-11-17
 

Hi,
It’s look like you forgot “<?php” at the beginning of your file Category.php (or you use short tag “<?” and your php conf need full tag “<?php")
Olivier

 
Magento Community Magento Community
Magento Community
Magento Community
 
wokka
Member
 
Total Posts:  45
Joined:  2008-06-06
 

Hi Olivier,

How stupid of me - many thanks for your quick response - all working peachy now grin

Thank you,
John

 
Magento Community Magento Community
Magento Community
Magento Community
 
Rdm
Member
 
Total Posts:  38
Joined:  2007-10-10
Ostrava
 

Hi,

import works, but in addition, I’d need to import my own category IDs, set them active/inactive, and to delete the category if it’s not in CSV and is in DB.
Is it possible to edit this import, or am I supposed to do it somehow else?

Thanks
Radim

 
Magento Community Magento Community
Magento Community
Magento Community
 
sharmstr
Member
 
Total Posts:  61
Joined:  2009-03-15
 

thanks to this post i’ve been able to import about 1000 categories.  the issue i’m having now is setting the URL Key during the import.  I’ve tried setURLKey, but nothing happens.

$cat = Mage::getModel(’catalog/category’)
->setStoreId($store->getId())
->setPath($path)
->setName($catName)
->setIsActive(1)
->setIsAnchor(1)
->setUrlKey($myURLKey)
->setDisplayMode($dispMode)
->save();

has anyone figured this out yet?

thanks

 
Magento Community Magento Community
Magento Community
Magento Community
 
Hucke_Media_de
Jr. Member
 
Avatar
Total Posts:  16
Joined:  2008-10-16
 

SOLVED:
Get funny problem

* Notice: Undefined index: categories in /var/www/shop.com/app/code/local/ImpCat/Catalog/Model/Convert/Adapter/Category.php on line 86

Categories seem to be OK in CSV file:

"store","category"
"default"
,"Abläufe & Abdeckungen/Belüftungselemente/Kamintüren"
"default"
,"Abläufe & Abdeckungen/Belüftungselemente/Möbellüfter"

SOLUTION: See above: “category” is wrong, has to be “categories”. One of these really stupid errs about to happen late at night wink

By the way: Thank you santhosh for contributing.

* Loaded successfully: “/var/www/shop.com/var/import/categories.csv”
* Starting Mage_Dataflow_Model_Convert_Parser_Csv :: parse
* Found 158 rows
* Starting catalog/convert_adapter_category :: parse
* Notice: Undefined index: categories in /var/www/shop.com/app/code/local/ImpCat/Catalog/Model/Convert/Adapter/Category.php on line 86
.....
* Notice: Undefined index: categories in /var/www/shop.com/app/code/local/ImpCat/Catalog/Model/Convert/Adapter/Category.php on line 86
* 100% 158/158 Einträge verarbeiten
* 0 Einträge importiert
* Profilausführung beendet.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Stefy
Member
 
Avatar
Total Posts:  36
Joined:  2009-03-30
 

Hi all..
somebody can help me please?…
I have always this error
“ Method “parse” not defined in adapter catalog/convert_adapter_category “

I’m crazying.... :(

Thank you…

 
Magento Community Magento Community
Magento Community
Magento Community
 
Hucke_Media_de
Jr. Member
 
Avatar
Total Posts:  16
Joined:  2008-10-16
 

Hello Stefy

Attached you will find a little archive which contains all mods and tricks described above to import categories as a CSV file.

I also had a little struggle putting the very helpful hints together.

Just put it into your app directory, create advanced import profile and should simply work.

File Attachments
ImpCat_Katalogdaten_importieren.tar  (File Size: 27KB - Downloads: 2908)
HowTo - ImpCat - Tool zum Importieren von Kategorien.txt  (File Size: 1KB - Downloads: 2503)
ImpCat - xml_fuer_advanced_profile_import_categories.txt  (File Size: 1KB - Downloads: 2497)
 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top
Page 2 of 12