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 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题