在我的应用程序中,我想通过iPhone应用程序在狂欢电子商务中订购产品。我轻松获取产品名称及其详细信息,但在创建产品订单时,它会在html页面中返回错误:
<h1>
TypeError
in Spree::Api::V1::OrdersController#create
</h1>
<pre>can't convert Symbol into Integer</pre>
我发送邮件请求为:
NSString *str = [NSString stringWithFormat:@"http://localhost:3000/api/orders"];
NSURL *urlForBuy = [NSURL URLWithString:[str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:urlForBuy];
NSString *idVariant = [NSString stringWithFormat:@"order[line_items][%d][variant_id]",0];
NSString *qnty = [NSString stringWithFormat:@"order[line_items][%d][quantity]",0];
NSString *idVariantValue = @"123456";
[request setPostValue:[NSString stringWithFormat:@"%d",[idVariantValue intValue]] forKey:idVariant];
[request setPostValue:[NSString stringWithFormat:@"%d",1] forKey:qnty];
[request setPostValue:@"<my admin token>" forKey:@"token"];
[request setRequestMethod:@"POST"];
[request setDelegate:self];
[request setDidFinishSelector:@selector(buyResponse:)];
[request setDidFailSelector:@selector(buyResponse_failed:)];
[networkQueue addOperation:request];
[networkQueue go];
另外,这个网址来自Spree的REST api文档:http://guides.spreecommerce.com/rest.html
另一件事我想知道这个网址中的[line_items]是什么...另外如果他们是除了上面的url之外的任何教程?...提前致谢。
答案 0 :(得分:0)
通过传递订单项来创建订单,如this test。
所示api_post :create, :order => {
:line_items => [
{
:variant_id => variant.to_param,
:quantity => 5
}
]
}
line_items
参数应该是一个哈希数组,由variant_id
和quantity
字段组成。 documentation表示请求如下所示:
POST /api/orders?order[line_items][0][variant_id]=1&order[line_items[0][quantity]=5
我希望这能帮助你更好地理解它!