iulianv Posted August 6, 2015 Share Posted August 6, 2015 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 More sharing options...
Simone Salerno Posted August 6, 2015 Share Posted August 6, 2015 Try this: $category = new Category; $category->id = 155; $category->active = 0; $category->id_parent = 15; $category->name = "category"; $category->link_rewrite = "one-category"; //this will force ObjectModel to use your ID $_GET['forceIDs'] = true; $category->add(); Link to comment Share on other sites More sharing options...
iulianv Posted August 6, 2015 Author Share Posted August 6, 2015 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?! Link to comment Share on other sites More sharing options...
Simone Salerno Posted August 27, 2015 Share Posted August 27, 2015 (edited) 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 August 27, 2015 by SimoneS93 (see edit history) Link to comment Share on other sites More sharing options...
vekia Posted August 30, 2015 Share Posted August 30, 2015 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 More sharing options...
vasylkhoma Posted September 19, 2019 Share Posted September 19, 2019 Can you please tell how to create the same functionality for 1.7? 1 Link to comment Share on other sites More sharing options...
Adam Piekarski Posted July 21, 2021 Share Posted July 21, 2021 Try: $cat->force_id = true; // Working in Prestashop 1.7.7.3 1 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