Magento: Import categories from cli

Monday April 16th, 2012

We often need to automate the creation of our Magento categories. This can be useful when you change the environment or after a complete reinstall. Here is a small script that allows you to create your category structure by importing a CSV file from the command line.

I’m having issues running the PHP script in XAMPP even though I added the path to php in the .profile file. When I run the script from the Terminal, it just prints out the code from the .php page to the Terminal.

Script is working well, all categories got inserted correctly. But is there a way to set all categories as anchor? I tried to put the ‘is-anchor’ to 1 in the file.
When i ran the code again the ‘is_anchor’ was still 0 + the name and active state were 0 too..

Hi,
I have this error when try to execute ?!Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or ‘}’ in /homepages/5/d295630334/htdocs/demo.webclik.tn/ fc-magento/shell/import_categories.php on line 19

Hi, I love the script by the way. I am writing because I used the upload, but the way I had my code written, it did not get all the categories loaded. Then when I was going to reload, the person setting up the navigation was freaking out because he did it according to a setting in the categories. I added the new categories manually and even though that is more work, it is fine. My problem is, if later on we want to add more categories through an upload like this, are we able to append what we already have if we don’t use force? I am scared to mess with it because I am not doing the php stuff and I do not want to make more work for someone else.
Thanks,
Tracy

Nice post. I used to be checking continuously this weblog and I’m impressed! Extremely useful information particularly the final phase I deal with such information much. I was seeking this certain information for a very long time. Thanks and good luck.

Nice work.
I only have one question regarding the CSV structure.
As far as i can understand I have to put my main category-tree on the left, but in the backend you can see the “website” as “top” category, but it doesn´t seem that you are putting this top-level category in your CSV. How is this handled here ? Do I have to “ignore” this top-category and doesn´t that mean multi-store environment is not supported ?
Thanks for any help!

Hi,
I ran the script, and it told me categories were already existing (although it was not the case) and i had to run –force
I ran the script with –force, and it correctly inserted my categories but… deleted all the others..
What did i do wrong ? ( i didn’t specify in the file any store or website, as i have only one website/store) …
Thanks