Jump to content

Create new Category using new Category in a php


iulianv

Recommended Posts

Hello,

 

i have a question if anyone could answer it.

 

i have a piece of code that creates a new category inside a custom script..

 

like so

 

$category = new Category;
$category->id_category = 155;
$category->active = 0;
$category->id_parent = 15;
$category->name = "category";
$category->link_rewrite = "one-category";
$category->add();

 

my problem is that the id_category = 155 is not inserted into the database .. it takes the next autoincremented id instead .. like 12 .. 13.. 15 ..

 

any ideas? Thanks.

Link to comment
Share on other sites

  • 3 weeks later...

Here's my working code (tested on PS 1.6.0.5):

        $_GET['forceIDs'] = true;
        $cat = new Category();
        $cat->id = 100;
        $cat->description = [ 1=> 'd' ];
        $cat->id_parent = 2;
        $cat->is_root_category = false;
        $cat->link_rewrite = [ 1=> 'lr' ];
        $cat->meta_description = [ 1=> 'md' ];
        $cat->meta_keywords = [ 1=> 'mk' ];
        $cat->meta_title = [ 1=> 'mt' ];
        $cat->name = [ 1=> 'name' ];
        $save = $cat->add();
        d([$save ? $save : 'error', $cat]);
Edited by SimoneS93 (see edit history)
Link to comment
Share on other sites

Thanks for the quick response Simone, but still no.

 

even with forceIDs=true still incremented ..

or $category = new Category(155);

or $category->id_category = 155;  :|

 

another approach?!

 

 

show the code you're trying to use, everything depends on it

Link to comment
Share on other sites

  • 4 years later...
  • 1 year later...

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...