xoriuz Posted February 20, 2011 Share Posted February 20, 2011 hello,i need to create a code to add new category / products,i've been trying to use category class, here is the code: $cat = new Category(NULL, NULL); $cat->name = "test"; $cat->active = true; $cat->description = "Testing purposes category"; $cat->id_parent = 0; if ($cat->validateFields() === true) { if ($cat->add()) { echo "success"; } else { echo "unsuccess"; } } the new category has been added into database, but i cant see it in the admin page..does anyone know something about it?is there anything wrong in my code? Link to comment Share on other sites More sharing options...
mbarreteau Posted February 25, 2011 Share Posted February 25, 2011 Hi !id_parent must be equal to 1active must be equal to 1name and description are multi-language fields, so you must specify in which lang you set the name.This code should work : $defaultLanguageId = intval(Configuration::get('PS_LANG_DEFAULT')); $cat = new Category(NULL, NULL); $cat->name[$defaultLanguageId] = "test"; $cat->active = 1; $cat->description[$defaultLanguageId] = "Testing purposes category"; $cat->id_parent = 1; if ($cat->validateFields() === true) { if ($cat->add()) { echo "success"; } else { echo "unsuccess"; } } Link to comment Share on other sites More sharing options...
xoriuz Posted February 25, 2011 Author Share Posted February 25, 2011 ooh ya the id_parent must be 1 XD no wonder it didnt show.thank you for your help Link to comment Share on other sites More sharing options...
justinl Posted October 18, 2011 Share Posted October 18, 2011 I just wanted to add that if you want to know the id of the category you just created, you can find it in $cat->id. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now