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, 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

Magento Forum

Import Categories from CSV file
Jr. Member
Total Posts:  1
Joined:  2009-03-18

The affiliate store, I have been working on since last week was still incomplete.
yesterday I figured out how to import external links in Magento and show them in the Catalogue view of Magento store.
Eventhough the data can be imported, it does have some categories which are defined as text, bbut not as id’s as preferred by the Magento Installation.
But If I’m to add any product just as a simple one but not as a configurable one, I would end up doing some extra manual work t import them by creating profiles
everytime I Import the data.
On the magento forums, user “amartinez” had written a nice script to import a datafeed of configurable products into Magento.It even had a part of code where
it would add the category if not defined in the database of Magento.
I would need to add the Category before hand in my case, and hence I modified that script to add categories.
I downloaded the list of categories from affiliate site, it has about 700 odd categories listed.

To scrutinize the data in the downloaded categories, I created a copy of the category downloaded with the below data.

store website category-level1 category-level2 categories
default default catA catB =concatenate(C1,”/”,D1) results in catA/catB

Now I created the advanced profile Buyatcategoryimport as

<action type=”dataflow/convert_adapter_io” method=”load”>
<var name=”type”>file</var>
<var name=”path”>var/import</var>
<var name=”filename”><![CDATA[categ1.csv]]></var>
<var name=”format”><![CDATA[csv]]></var>

<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_buyatcategoryimport</var>
<var name=”method”>parse</var>

and my php convertparser script named it as Buyatcategoryimport.php

The content for saveRow function that goes into my script is as below.


public function saveRow(array $importData)

echo $importData[’store’],$importData[’categories’]
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’);
} else {
$store = $this->getStoreByCode($importData[’store’]);

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

//// Para importar categorias
if (isset($importData[’categories’])) {
$categoryIds = $this->_addCategories($importData[’categories’], $store);


return true;

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