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 基于pso参数优化的LightGBM分类模型
  • ¥15 安装Paddleocr时报错无法解决
  • ¥15 python中transformers可以正常下载,但是没有办法使用pipeline
  • ¥50 分布式追踪trace异常问题
  • ¥15 人在外地出差,速帮一点点
  • ¥15 如何使用canvas在图片上进行如下的标注,以下代码不起作用,如何修改
  • ¥15 Windows 系统cmd后提示“加载用户设置时遇到错误”
  • ¥50 vue router 动态路由问题
  • ¥15 关于#.net#的问题:End Function
  • ¥15 无法import pycausal