Simple example on how to programatically create two level categories in Magento

Recently I have been working on a new site that has large number of products and not so little number of categories. As you all know, Magento import system is somewhat obscure, does not seem to allow you a lot in terms of modifications. You are bound to creating a proper CSV file in order to do a valid import. One of the difficulties with such system often comes down to “how do I transfer all my categories” or “how to I transfer all my images” from old shop system to Magento. My so far practice has simple answer on that: Sometimes, there just isn’t any simply solution. Sometimes you will waste hours of coding just to build a proper CSV file that will later be passed to the import system.

This shop I was working on was relatively “flat” in its architecture. Flat in terms that it had just a few tables, with not so great “normalization”. However, this “flat” architecture produced a lightning fast web shop with speed of page loading that Magento can most of the time dream of, unless placed on truly quality server.

So, how do we transfer the categories from old shop system to the Magento. We all know that Magento CSV file requires category id’s to be placed in the appropriate CSV column. That means we need to have our categories created in front. Here is a simple example on how to programatically create two level categories in Magento.

Please not that the example above is not generally applicable. You will notice that I used it to programatically create only the two level category system. Thus, the example is not to be used as simply “copy-paste”.

Depending on the size (number) of the categories in the old shop, programatically in place of manually creating categories can save you great deal of time.

Hi,
thanks for sharing your interesting code!
I’ve “upgraded” it to be used for three levels and use of different queries.
Now i need to execute the metod but i can’t find any example… can you suggest me how?

Your email address will not be published. Required fields are marked *

Comment

You may use these HTML tags and attributes: <a href="" title=""> <blockquote cite=""> <code> <del datetime=""> <em> <s> <strike> <strong>. You may use following syntax for source code: <pre><code>$current = "Inchoo";</code></pre>.