Currently I'm developing a php scipt to import and keep synced a prestashop database with data coming from a management software.
Is it a good method to insert data directly on the database or is it better to use the prestashop classes.
Can you give an exemplo how to import categories with class method ?
Kind regards
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();
It's much reliable to use classes to reach your goal. Because you avoid all issues which can occur if versions of your prestashop instances will be different. With classes, you won't damage a database and won't confuse your data and also during the import, all data will be validated by classes. The example above seems to be correct and depends only on the number of fields that you want to import
Copied above
$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();