Php 我想通过代码在Prestashop上添加x个客户,但需要额外的字段
我试图用代码添加客户,但PrestaShop给了我一个bug。 Im使用PHP和XMLPhp 我想通过代码在Prestashop上添加x个客户,但需要额外的字段,php,xml,web-services,prestashop,customer,Php,Xml,Web Services,Prestashop,Customer,我试图用代码添加客户,但PrestaShop给了我一个bug。 Im使用PHP和XML $XMLRQString = '<?xml version="1.0" encoding="utf-8"?>'. '<x:Winmax4GetEntitiesRQ xmlns:x="urn:Winmax4GetEntitiesRQ">'. '</x:Winmax4GetEntitiesRQ >';
$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();
}
$XMLRQString=''。
''.
'';
$Params=数组(
'公司代码'=>'',
'用户登录'=>'',
'用户密码'=>'',
“Winmax4GetEntitiesRQXML”=>$XMLRQString
);
$return=$client->GetEntities($Params);
$XMLRSString=新的SimpleXMLElement($return->GetEntitiesResult);
foreach($XMLRSString->Entities->Entity as$Entity)
{
$default_lang=Configuration::get('PS_lang_default');
$customer=新客户();
$customer->email=$entity->email;
$customer->lastname=$entity->EntityType;
$customer->firstname=[$default\u 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(数组(对象(SimpleXMLElement)))处
ObjectModel.php第1149行
在ObjectModelCore->validateField('firstname')中,
ObjectModel.php第981行中的数组(对象(SimpleXMLElement))
在ObjectModel.php第284行的ObjectModelCore->validateFields()处
在ObjectModel.php第551行的ObjectModelCore->getFields()处
在Customer.php第264行的ObjectModelCore->添加(true,true)
在create_clients.php第66行的CustomerCore->add()处
在存储SimpleXML中的值时,如果您仅通过元素的标记名引用元素本身,那么这将是SimpleXMLElement的一个实例。由于需要元素的实际内容,最简单的方法是将其转换为字符串
$customer->firstname= (string)$entity->Name;
您是否尝试过
$customer->firstname=(字符串)$entity->Name代码>哈哈,非常感谢