douyin7416 2013-11-19 10:42
浏览 56
已采纳

将php代码转换为objectiveC [关闭]

Hi I've this php code:

$proxy = new SoapClient('http://magentohost/api/soap/?wsdl');
$sessionId = $proxy->login('apiUser', 'apiKey');

$quoteId = $proxy->call( $sessionId, 'cart.create');

$arrProducts = array(
    array(
        “product_id” => “1”,
        “qty” => 2
    );

$resultCartProductAdd = $proxy->call(
    $sessionId,
    “cart_product.add”,
    array(
        $quoteId,
        $arrProducts
    )
);

I need to use it in my iOS app so I'm getting the sessionId and the quoteId by using a library. The library that I'm using work so: Magento gives me this api: customer.create and I've to set in customer create the sessionId and an array in which I put the details of the customer. In objectiveC I'm getting this code:

[Magento call:@[@"customer.create", @{
     @"email": email,
     @"password": password,
     @"firstname": firstname,
     @"lastname": lastname,
     @"website_id": @1,
     @"store_id": Magento.service.storeID
}] success:^(AFHTTPRequestOperation *operation, id responseObject) {
    Magento.service.customerID = responseObject;
    NSLog(@"signUp customerID = %@", Magento.service.customerID);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    NSLog(@"error %@", error.localizedDescription);
}];

Now I'm guessing that my library convert a php array to a NSDictionary (look the code above). How I can transform the php array of array (by using this library) in objectiveC? I've to use the cart_product.add magento api. I hope you can understand what I mean and I hope you can help me.

  • 写回答

1条回答 默认 最新

  • dua55014 2013-11-22 10:32
    关注

    Solved by myself, here's the code:

    [Magento call:@[@"cart_product.add", Magento.service.cartID,@[@{@"product_id": productID, @"qty": self.qty}]]
                            success:^(AFHTTPRequestOperation *operation, id responseObject) {
                                NSLog(@"Prodotto aggiunto");
                                [Magento call:@[@"cart.info", @{@"quoteId": Magento.service.cartID}]
                                      success:^(AFHTTPRequestOperation *operation, id responseObject) {
                                          [self getListOfProductsInCart:responseObject];
                                      }failure:^(AFHTTPRequestOperation *operation, NSError *error) {
                                          NSLog(@"Errore: %@", error.localizedDescription);
                                      }];
    

    With this code converted the php you saw in my question to objectiveC. I hope this will be useful for someone

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化