在 prestashop 上导入类别和产品

Import categories and products on prestashop

我正在开发一个 php 脚本来导入 prestashop 数据库并与来自管理软件的数据保持同步。

直接在数据库中插入数据是好方法还是使用prestashop更好classes.

能否举例说明如何使用class方法导入类别?

试试这个:

$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();

使用类达到您的目标是非常可靠的。因为如果您的 prestashop 实例的版本不同,您可以避免所有可能发生的问题。使用 类,您不会损坏数据库,也不会混淆您的数据,而且在导入期间,所有数据都将由 类 验证。上面的示例似乎是正确的,并且仅取决于您要导入的字段数

以上复制

$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();