1

This is the scenario:

  1. I am making a SOAP call from Magento to a CMS
  2. The CMS will produce and return a json encoded object of new Category names and some category properties ( Title, URL, Parent/Child relationship, that's pretty much it ) to Magento.

  3. I need to iterate through this object, and take the Category names and insert them into the Magento DB so that Magento can manage these categories. I will also need to add whatever category properties to each category that aren't present in the object, and I need to correctly insert these Categories so that they show up in the admin section under Manage Categories.

My Question: I just need to know how to work with Magento's API to insert the Categories into the database correctly. Can anyone point me in the right direction?

Note: I'm using Magento CE 1.6.1.0. Using a plugin won't work in my case, because I need this to happen seamlessly to the user logging into the admin area. If there's a plugin someone knows of that is open source and has the functionality in it that I'm looking for, please share the name so I can study that code.

Thanks for any help!

1

Magento also has an API, accessible via SOAP and XML-RPC, and it includes the ability to create a category.

If you're not interested in learning how to make a SOAP call into Magento, you can take a look at the implementation of the category create method at

#File: app/code/core/Mage/Catalog/Model/Category/Api.php
public function create($parentId, $categoryData, $store = null)
{
    //...PHP code to create a category is here
}

and you could call the category create method manually with something like this

Mage::getModel('catalog/category_api')->create($parentId, $categoryData);

I've never seen a full explanation of the raw database structure behind categories, which is extra confusing given it's both EAV, and representing a tree structure in a SQL table. I wouldn't attempt a category insert via raw SQL calls.

2
  • Thank you providing me with this answer! I have another question, how could I get my code to run as the Manage Categories section of the admin panel is loaded up? So if someone were to go into the admin section, click on Manage Categories, I'd like to have my code executed at that point. Is this something I'd do with an observer? I'm thinking that doing it in an event driven way would be good. Any insight you could offer would be great! Thank you again!
    – ryanF
    Sep 24 '13 at 18:03
  • 1
    @ryanF Sounds like a good new question for this site.
    – Alan Storm
    Sep 24 '13 at 22:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.