Jump to content

how to create a category from a module?


seaotter

Recommended Posts

Hi!!! I'm trying to create a category from a module with this code:

 

$c = new Category();
$c->active = 1;
$c->name = "Test Category";
$c->id_parent = 1;
$c->description = "Description";
$c->add();
$c->update();
$c->save();

 

The category is created, is displayed under the Home category, i can edit it, add products to it etc.

 

The problem is: the name always is stored as "e" and the description "c".

 

What am i doing wrong????

Link to comment
Share on other sites

Thanx for the quick response.

 

I had tried with:

 

$c->name = array((int)(Configuration::get('PS_LANG_DEFAULT')) => "Test Category");
$c->description = array((int)(Configuration::get('PS_LANG_DEFAULT')) => "Description");

 

but had not worked.

 

Anyway, changing some of your answer worked perfectly.

 

$lang_id = (int)(Configuration::get('PS_LANG_DEFAULT'));
...
$c->name[$lang_id] = "Test Category";
$c->description[$lang_id] = "Description";

 

Thanx again

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...