[以编程方式使用Import csv函数的Prestashop 1.7

问题描述 投票:0回答:1

我声明我不熟悉Prestashop,并且使用的是1.7.6版。我试图了解如何在不使用用户界面的情况下使用csv文件中的导入功能。我试图在可能的网络api上查找文档,但未找到任何内容。

我想完成的是以下情况:我在同一台服务器上有两个Web应用程序/ my_webapp/ my_prestashop

通过“ my_webapp”,我收到一个csv文件,对其进行处理并生成一个新的csv文件。现在继续在“ my_webapp”中运行该过程,我想实例化prestashop应用程序的环境,以通过将刚刚创建的新文件传递给import csv函数来调用它。

在网上搜索后,我发现了一些示例代码,但是,尝试使用和修改它,我没有使它起作用。例如,在“ my_webapp”文件夹中,我仅创建一个“ myimport.php”文件,并使用两个GET参数进行调用。以下是电话:

localhost/my_webapp/myimport.php?csv=prod.csv&limit=5

注意:文件“ prod.csv”已打开“管理文件夹的路径” /导入

“ 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
1个回答
0
投票
if (!defined('_PS_ADMIN_DIR_')) {
    define('_PS_ADMIN_DIR_', __DIR__);
}
include _PS_ADMIN_DIR_.'/../config/config.inc.php';

if (!Context::getContext()->employee->isLoggedBack()) {
    Tools::redirectAdmin(Context::getContext()->link->getAdminLink('AdminLogin'));
}
© www.soinside.com 2019 - 2024. All rights reserved.