[英]Magento - How to add extra button like “Add to cart” and Redirect to external url from grid view, list view and product page view.
[英]How to redirect Add to cart url page
我有一個用於電子商務並將產品ID和數量添加到addCart的應用程序。 在這里,我正在檢查靜態樣本值,並將此值傳遞給url以進行檢查。 如果此值匹配,我需要重定向以添加到購物車網址頁面。 在瀏覽器中可以正常工作。 但是在移動應用程序中,當我單擊按鈕時,我需要檢查值是否相同,我需要重定向。 但這不是重定向。
int i=2;
NSString *post =[[NSString alloc] initWithFormat:@"password=%d",i];
NSLog(@"PostData: %@",post);
NSURL *url=[NSURL URLWithString:[NSString stringWithFormat:@"http://serverurl.net/projects/AR/create_cart.php?id=%d",i]];
NSLog(@"url is %@",url);
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:url];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];
// [NSURLRequest setAllowsAnyHTTPSCertificate:YES forHost:[url host]];
NSError *error = [[NSError alloc] init];
NSHTTPURLResponse *response = nil;
NSData *urlData=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSString *responseData = [[NSString alloc]initWithData:urlData encoding:NSUTF8StringEncoding];
NSLog(@"Response code: %d", [response statusCode]);
if ([responseData length]){
NSLog(@"Response ==> %@", responseData);
NSMutableDictionary *dict=[responseData JSONValue];
NSLog(@"dict is %@",dict);
NSInteger success = [(NSNumber *) [dict objectForKey:@"success"] integerValue];
NSLog(@"%d",success);
if(success == 1){
}
目前尚不清楚您使用的是哪個電子商務平台。 萬一碰巧是Magento,可以通過以下方法重定向用戶以在iOS應用中登錄: https : //github.com/mobstac/JustPaws/blob/master/MobstacShop/AuthViewController.m 。
我們遇到了同樣的問題,並通過捕獲WebView的響應來解決了它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.