PrestaShop创建客户
我有这段代码,我正在尝试使用prestashop模式在我的网站上创建一个新客户。但我的回答总是出错PrestaShop创建客户,prestashop,Prestashop,我有这段代码,我正在尝试使用prestashop模式在我的网站上创建一个新客户。但我的回答总是出错 NSString *xmlPath = [[NSBundle mainBundle] pathForResource:@"Login" ofType:@"xml"]; NSString *xmlStr = [[NSString alloc] initWithContentsOfFile:xmlPath encoding:NSUTF8StringEncoding error:nil];
NSString *xmlPath = [[NSBundle mainBundle] pathForResource:@"Login" ofType:@"xml"];
NSString *xmlStr = [[NSString alloc] initWithContentsOfFile:xmlPath encoding:NSUTF8StringEncoding error:nil];
NSString *encodedurlstring = (__bridge NSString*) CFURLCreateStringByAddingPercentEscapes (NULL, (__bridge CFStringRef) xmlStr, NULL, (CFStringRef)@"!*'();:@&=+$,/?%#[]",kCFStringEncodingUTF8);
NSString *urlStr = [NSString stringWithFormat:@"http://passkey:@farma-web.it/api/customers/?Xml=%@",encodedurlstring];
NSURL *webURL = [NSURL URLWithString:urlStr];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:webURL];
[request setHTTPMethod:@"POST"];
[request setValue: @"text/xml" forHTTPHeaderField: @"Content-Type"];
NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSString *response = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];
NSLog(@"response - %@",response);
我附加的XML是
<prestashop>
<customers>
<customer>**I DO NOT KNOW WHAT TO WRITE HERE**</customer>
<email>abc@abc.com</email>
<passwd>12344321</passwd>
<firstname>ABC</firstname>
<lastname>DEF</lastname>
</customers>
</prestashop>
**我不知道在这里写什么**
abc@abc.com
12344321
基础知识
DEF
我得到的回应是
<?xml version="1.0" encoding="UTF-8"?>
<prestashop xmlns:xlink="http://www.w3.org/1999/xlink">
<errors>
<error>
<message><![CDATA[Internal error. To see this error please display the PHP errors.]]></message>
</error>
</errors>
</prestashop>
“客户”不是一个独立的字段,而是一个容器,包含所有其他字段,如firstname、lastname、email等
创建客户的最佳方法是检索并填写空白表格,并用您的数据填写:我遇到了类似的问题,以下是我在prestashop 1.6.0.9版中发现的内容: 1) 正如@adrien-g所指出的,从
define(“PS\u MODE\u DEV”),更改为false代码>定义(“PS模式开发”,true);
2) 接下来,您将看到更多有意义的错误,如使用此CURL命令模拟的错误:
$ curl -kv https://myprestashop.bitnamiapp.com/prestashop/api/customers?ws_key=secret -d '
<?xml version="1.0" encoding="UTF-8"?><customer><lastname>blue</lastname><firstname>boy</firstname><email>boy@blue.com</email></customer>'
...
<message><![CDATA[parameter "passwd" required]]></message>
...
值得注意的是:
- 使用
与xml=
对我使用的版本没有任何影响
- 使用
和
对我使用的版本没有任何区别
我也遇到了同样的问题,如果你解决了这个问题,请分享!嘿,首先在你的prestashop上启用调试日志。要执行此操作,请编辑此文件$(PrestashopDirectory)/config/settings.inc.php并设置define('PS_MODE_DEV',true);我仍然无法创建新客户。我现在还在做一些研究。但是我已经成功地完成了地址部分,以防您需要我在这个API中的帮助。
$ curl -kv https://myprestashop.bitnamiapp.com/prestashop/api/customers?ws_key=secret -d '
<?xml version="1.0" encoding="UTF-8"?>
<prestashop xmlns:xlink="http://www.w3.org/1999/xlink">
<customer><lastname>blue</lastname><firstname>boy</firstname><email>boy@blue.com</email>
<passwd>mysecret</passwd>
</customer>
</prestashop>'
...
<?xml version="1.0" encoding="UTF-8"?>
<prestashop xmlns:xlink="http://www.w3.org/1999/xlink">
<customer><id><![CDATA[3]]></id>...</customer></prestashop>
...