【发布时间】:2019-10-10 22:28:59
【问题描述】:
我正在尝试使用代码添加客户,但 PrestaShop 给了我一个错误。 我使用 PHP 和 XML
$XMLRQString = '<?xml version="1.0" encoding="utf-8"?>'.
'<x:Winmax4GetEntitiesRQ xmlns:x="urn:Winmax4GetEntitiesRQ">'.
'</x:Winmax4GetEntitiesRQ >';
$Params=array(
'CompanyCode'=>'',
'UserLogin'=>'',
'UserPassword'=>'',
'Winmax4GetEntitiesRQXML'=> $XMLRQString
);
$return = $client->GetEntities($Params);
$XMLRSString = new SimpleXMLElement($return->GetEntitiesResult);
foreach ($XMLRSString->Entities->Entity as $entity)
{
$default_lang= Configuration::get('PS_LANG_DEFAULT');
$customer=new Customer();
$customer->email= $entity->Email;
$customer->lastname= $entity->EntityType;
$customer->firstname= [$default_lang => $entity->Name];
$customer->contribuinte= $entity->TaxPayerID;
$customer->passwd= $entity->TaxPayerID;
$customer->active = 1;
$customer->add();
}
错误:(1/1) ContextErrorException 警告:preg_match() 预期 参数2为字符串,给定数组
在 Validate.php 第 172 行
在 ValidateCore::isCustomerName(array(object(SimpleXMLElement))) 中 ObjectModel.php 第 1149 行
在 ObjectModelCore->validateField('firstname', ObjectModel.php 第 981 行中的数组(对象(SimpleXMLElement)))
在 ObjectModelCore->validateFields() 中 ObjectModel.php 第 284 行
在 ObjectModelCore->getFields() 中 ObjectModel.php 第 551 行
在 ObjectModelCore->在 Customer.php 第 264 行添加(true, true)
在 CustomerCore->add() 在 create_clients.php 第 66 行
【问题讨论】:
-
你试过
$customer->firstname= (string)$entity->Name; -
大声笑,非常感谢
标签: php xml web-services prestashop customer