0

I'm developing a php script 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 exemple how to import categories with class method?

2 Answers 2

0

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();
3
  • 1
    Thank for your answer. I already did that and it works like a charm. now I'm tring to upload various images to products. I have them in a folder inside /img and I need to make a script to change the names and put them in the right place. Do you know the prestashop to do that? Dec 7, 2018 at 14:30
  • you have to make another post for that problem, i have the answer but in the comments the number of characters is limited. Dec 7, 2018 at 14:45
  • 1
    Thank you guys I fixed the problem! Dec 20, 2018 at 12:27
0

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();
1
  • Thank for your answer. I already did that and it works like a charm. now I'm tring to upload various images to products. I have them in a folder inside /img and I need to make a script to change the names and put them in the right place. Do you know the prestashop to do that? Dec 7, 2018 at 14:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.