在我的app中,我想通过iPhone app在狂欢电商中订购一款产品。我很容易获得产品名称和它们的详细信息,但是在为产品创建订单时,它在html页面中返回错误:
<h1>
TypeError
in Spree::Api::V1::OrdersController#create
</h1>
<pre>can't convert Symbol into Integer</pre>
我将post请求发送为:
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文档中得到的这个url是:http://guides.spreecommerce.com/rest.html
我想知道的另一件事是这个url中的line_items是什么。此外,如果他们是任何教程,除了上述url?...Thanks提前。
发布于 2012-07-12 15:06:50
订单通过API通过传入行项目来创建,如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
我希望这能帮助你更好地理解它!
https://stackoverflow.com/questions/11445275
复制相似问题