2012-07-12 49 views
0

在我的應用程序中,我想通過iPhone應用程序訂購電子商務電子商務產品。我輕鬆地拿到產品的名字和他們的細節,但同時對產品創建順序是在HTML頁面返回錯誤:使用iOS應用程序創建訂單以施展電子商務

<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]; 

而且,這個網址我得到從REST api文檔的施普雷這是:http://guides.spreecommerce.com/rest.html

另一件事,我想知道什麼是在這個網址[line_items] ...另外,如果他們是除了上面的網址之外的任何教程?...在​​此先感謝。

回答

0

訂單通過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 

我希望可以幫助您更好地理解它!

+0

感謝您的回覆...你可以請看看我的參數,因爲我認爲他們不正確..在這裏我發送兩個參數... iekey => value(「order [line_items] [0] [variant_id] => 12345「和」order [line_items] [0] [quantity] => 1「)...它們是否合併? – 2012-07-12 07:26:34

+0

等待回覆.pls幫助 – 2012-07-12 08:59:16

+0

您在首次發表評論後發佈了「等待回覆」*一小時*。期待另一個響應立即有點粗魯。我不是你個人的犯罪。 – 2012-07-12 23:25:24

相關問題