Php PrestaShop:通过web服务更新客户

Php PrestaShop:通过web服务更新客户,php,web-services,prestashop,prestashop-1.6,Php,Web Services,Prestashop,Prestashop 1.6,我想使用Web服务更新PrestaShop中的客户。我根据客户的电子邮件和公司名称搜索客户,然后更新新的详细信息。但是,当我使用过滤器获取客户详细信息并进行更新时,我收到以下错误,我不确定如何解决此问题 错误90-修改资源时需要id 代码 $email=$_POST['email']; $oldEmail=$_POST['oldEmail']; $company=$_POST['company']; try { $webService = new PrestaShopWebservic

我想使用Web服务更新PrestaShop中的客户。我根据客户的电子邮件和公司名称搜索客户,然后更新新的详细信息。但是,当我使用过滤器获取客户详细信息并进行更新时,我收到以下错误,我不确定如何解决此问题

错误90-修改资源时需要id

代码

$email=$_POST['email'];
$oldEmail=$_POST['oldEmail'];
$company=$_POST['company'];

try
{
    $webService = new PrestaShopWebservice(PS_SHOP_PATH, PS_WS_AUTH_KEY, DEBUG);

    $opt = array(
        'resource' => 'customers',
        'display' => 'full',
        'filter[email]'=>'e.siona@example.gr',//['.$oldEmail.']',
        'filter[company]'=>'euro'//['.$company.']'
    );

    $xml = $webService->get($opt);

    // Retrieve resource elements in a variable (table)
    $resources = $xml->children()->children();
    //$opt['id'] = 17;
    //echo $resources->id;
}
catch (PrestaShopWebserviceException $e){
    // Here we are dealing with errors
    $trace = $e->getTrace();
    if ($trace[0]['args'][0] == 404) echo 'Bad ID';
    else if ($trace[0]['args'][0] == 401) echo 'Bad auth key';
    else echo 'Other error';
}

$resources->email = 'e.siona43@example.gr';

// Resource definition
$opt = array('resource' => 'customers');

//XML file definition
$opt['putXml'] = $xml->asXML();

$opt['id'] = 'How can I put here the id retrieved from previous call?'; 

// Calling asXML() returns a string corresponding to the file
$xml = $webService->edit($opt);

// Second : We update the data and send it to the web service
示例中有一个错误

请尝试以下代码段的更正版本:

$email=$_POST['email'];
$oldEmail=$_POST['oldEmail'];
$company=$_POST['company'];

try
{
    $webService = new PrestaShopWebservice(PS_SHOP_PATH, PS_WS_AUTH_KEY, DEBUG);

    // Filters must be an array (I'll suggest this method)
    $filter = array(
        'email' => $oldEmail,
        'company' => 'ACME'
    );
    // I guess it's useless to use company because the e-mail it's a KEY in the database, so the correspondence 'should' be univocal.

    $opt = array(
        'resource' => 'customers',
        'display' => 'full',
        'filter' => $filter
    );

    $xml = $webService->get($opt);

    // Retrieve resource elements in a variable (table)
    $resources = $xml->children()->children();
}
catch (PrestaShopWebserviceException $e){
    // Here we are dealing with errors
    $trace = $e->getTrace();
    if ($trace[0]['args'][0] == 404) echo 'Bad ID';
    else if ($trace[0]['args'][0] == 401) echo 'Bad auth key';
    else echo 'Other error';
}
// Here we retrieve the ID
$customer_id = $resources->customer->id; 

// Here we update the e-mail
$resources->customer->email = $email; // E.g. 'e.siona43@example.gr';

// And call the web service
try
{
    $opt = array('resource' => 'customers');
    $opt['putXml'] = $xml->children()->asXML(); // This is correct if you have one customer in the XML. The GitHub examples it's incomplete and you get the error 90.
    $opt['id'] = $customer_id;
    $xml = $webService->edit($opt);
    // if WebService don't throw an exception the action worked well and we don't show the following message
    echo "Successfully updated.";
}
catch (PrestaShopWebserviceException $ex)
{
    // Here we are dealing with errors
    $trace = $ex->getTrace();
    if ($trace[0]['args'][0] == 404) echo 'Bad ID';
    else if ($trace[0]['args'][0] == 401) echo 'Bad auth key';
    else echo 'Other error<br />'.$ex->getMessage();
}
$email=$\u POST['email'];
$oldmail=$_POST['oldmail'];
$company=$_POST['company'];
尝试
{
$webService=新的PrestaShopWebservice(PS\u SHOP\u路径,PS\u WS\u AUTH\u密钥,调试);
//过滤器必须是数组(我建议使用这种方法)
$filter=数组(
'email'=>$oldmail,
“公司”=>“ACME”
);
//我想使用company是没有用的,因为电子邮件是数据库中的一个键,所以通信“应该”是单音的。
$opt=数组(
“资源”=>“客户”,
'显示'=>'完整',
'filter'=>$filter
);
$xml=$webService->get($opt);
//检索变量(表)中的资源元素
$resources=$xml->children()->children();
}
捕获(PrestaShopWebserviceException$e){
//这里我们处理的是错误
$trace=$e->getTrace();
如果($trace[0]['args'][0]==404)回显'Bad ID';
else if($trace[0]['args'][0]==401)回显'Bad auth key';
否则回显“其他错误”;
}
//这里我们检索ID
$customer\u id=$resources->customer->id;
//我们在这里更新电子邮件
$resources->customer->email=$email;//例如“E”。siona43@example.gr';
//并调用web服务
尝试
{
$opt=array('resource'=>'customers');
$opt['putXml']=$xml->children()->asXML();//如果xml中有一个客户,则这是正确的。GitHub示例表明,这是不完整的,您会得到错误90。
$opt['id']=$customer\u id;
$xml=$webService->edit($opt);
//如果WebService没有抛出异常,那么该操作运行良好,我们不会显示以下消息
echo“已成功更新。”;
}
捕获(PrestaShopWebserviceException$ex)
{
//这里我们处理的是错误
$trace=$ex->getTrace();
如果($trace[0]['args'][0]==404)回显'Bad ID';
else if($trace[0]['args'][0]==401)回显'Bad auth key';
else回显“其他错误
”。$ex->getMessage(); }

希望这有帮助:)

谢谢!我会试试,我会把结果贴在这里!