【发布时间】:2020-02-07 17:13:47
【问题描述】:
我声明我不熟悉 Prestashop,我使用的是 1.7.6 版本。
我正在尝试了解如何在不使用用户界面的情况下使用 csv 文件中的导入功能。
我试图在可能的 web api 上查找文档,但什么也没找到。
我想要完成的是以下场景:
我在同一台服务器上有两个 Web 应用程序
/my_webapp
/my_prestashop
通过“my_webapp”,我收到一个 csv 文件,对其进行处理并生成一个新的 csv 文件。
现在继续在“my_webapp”中运行该进程,我想实例化 prestashop 应用程序的环境,以通过将刚刚创建的新文件传递给导入 csv 函数来调用它。
在网上搜索我找到了一些示例代码,但尝试使用和调整它,我没有让它工作。
例如,在“my_webapp”文件夹中,我只需创建一个“myimport.php”文件并使用两个 GET 参数调用它。
以下是调用:
localhost/my_webapp/myimport.php?csv=prod.csv&limit=5
注意:文件“prod.csv”已打开
“管理文件夹的路径”/import
“myimport.php”文件内容:
<?php
$rootPrestashop = '/var/www/html/my_prestashop”;
define('_PS_ADMIN_DIR_', $rootPrestashop.'/admin_shop'); //not sure if this instruction is needed
$pathConfig = $rootPrestashop.'/config/config.inc.php';
$initConfig = $rootPrestashop.'/init.php';
require_once($pathConfig);
require_once($initConfig); //this line throw an error and then I can't test the others!
$importCtrl = new AdminImportControllerCore();
$crossSteps = array();
$limit = $_GET["limit"];
$importCtrl->productImport(false, $limit, $crossSteps, true, 0);
这是我正在尝试做的,但我未能初始化环境。
也许我走错了路,但有更好的方法。
我问是否有人可以帮助我了解我是否可以执行此过程以及正确的方法是什么。
提前致谢
【问题讨论】:
标签: php csv prestashop-1.7