PrestaShop 创建客户 [英] PrestaShop create customer
问题描述
我有这个代码,我试图使用 prestashop 模式在我的网站上创建一个新客户.但是我一直在响应中出错
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];[请求 setHTTPMethod:@"POST"];[请求 setValue:@"text/xml" forHTTPHeaderField: @"Content-Type"];NSData *returnData = [NSURLConnection sendSynchronousRequest:请求返回响应:nil 错误:nil];NSString *response = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];NSLog(@"响应 - %@",响应);
我附上的 XML 是
<客户><客户>**我不知道该写什么**</客户><email>abc@abc.com</email><passwd>12344321</passwd><firstname>ABC</firstname><lastname>DEF</lastname></客户></prestashop>
我得到的回应是
<message><![CDATA[内部错误.要查看此错误,请显示 PHP 错误.]]></message></错误></错误></prestashop>
我遇到了类似的问题,这是我在 prestashop 1.6.0.9 版中发现的:
1) 正如@adrien-g 指出的,从 define('_PS_MODE_DEV_', false);
更改为 define('_PS_MODE_DEV_', true);http://doc.prestashop.com/display/PS16/Setting+Up+Your+Local+Development+Environment#SettingUpYourLocalDevelopmentEnvironment-Displayingerrormessages
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[需要参数passwd"]]></message>...
3) 然后一些实验,例如添加 passwd
和 prestashop
标签,最终将引导您走上一条成功创建客户的道路:
$ 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></客户></prestashop>'...<?xml version="1.0" encoding="UTF-8"?><prestashop xmlns:xlink="http://www.w3.org/1999/xlink"><客户><id><![CDATA[3]]></id>...</customer></prestashop>...
值得注意:
- 使用
<?xml ...><prestashop></prestashop>
对比 xml=<?xml ...><prestashop></prestashop>
在我玩过的版本中没有任何区别. - 使用
与
没有对我玩过的版本有什么影响.
I have this code where I am trying to create a new customer on my website using prestashop mode. But I keep getting error in the response
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);
The XML that I have attached is
<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>
The response that I am getting is
<?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>
I ran into similar issues and here's what I found out on prestashop version 1.6.0.9:
1) As @adrien-g points out, change from define('_PS_MODE_DEV_', false);
to define('_PS_MODE_DEV_', true);
http://doc.prestashop.com/display/PS16/Setting+Up+Your+Local+Development+Environment#SettingUpYourLocalDevelopmentEnvironment-Displayingerrormessages
2) Next you will start seeing more meaningful errors like the one simulated with this CURL command:
$ 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>
...
3) Then some experimentation like adding the passwd
and prestashop
tags will finally lead you down a path where you see customers successfully being created:
$ 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>
...
Worth noting:
- using
<?xml ...><prestashop></prestashop>
versus xml=<?xml ...><prestashop></prestashop>
doesn't make any difference in the version I played around with. - using
<prestashop>
versus<prestashop xmlns:xlink="http://www.w3.org/1999/xlink">
doesn't make any difference in the version I played around with.
这篇关于PrestaShop 创建客户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!