简体   繁体   中英

Sudzc: How to pass arguments or parameters to function?

Have searched a lot but am unable to find an example for my query.

I have successfully integrated sudzc code into my project but am not able to figure out a way to pass arguments to the function:

// Returns id
/* Call api functionality */
[service call:self action:@selector(callHandler:) sessionId: @"" resourcePath: @"" args: @"???"];

Can someone please show me a way with an example if worked with sudzc.

Thanks in advance.

I figured it myself. There is not reference given by Sudzc themselves, as to how pass arguments to the functions. I also did extensive research on the internet, but you wont find any hint. So don't waste your time there.

The answer to this issue is to create the filter module yourself in the form of an NSString. In some posts, somebody mentioned that we need to pass an array. That's something that Sudzc people have not implemented yet and to be honest wasn't able to understand what they wanted us to implement ourselves.

From the site of Magento, I found a module of SOAP where it shows the structure of filter arguments.

http://www.magentocommerce.com/api/soap/sales/salesOrder/sales_order.list.html

At the bottom of the link, there is the structure for the soap request given, which I didn't find anywhere else. That gave me an idea. So I wrote the following functions for generating them:

-(NSMutableString *)prepareFilter:(NSMutableArray *)items
{
    // Prepare args string
    NSMutableString *s = [NSMutableString string];
    [s appendString:[NSString stringWithFormat:@"<filter SOAP-ENC:arrayType=\"ns1:associativeEntity[%d]\" xsi:type=\"ns1:associativeArray\">", items.count]];

    // Add normal filter
    for (int cnt=0; cnt<items.count; cnt++)
    {
        [s appendString:@"<item xsi:type=\"ns1:associativeEntity\">"];
        [s appendString:[NSString stringWithFormat:@"<key xsi:type=\"xsd:string\">%@</key>",[[items objectAtIndex:cnt] objectForKey:@"Key"]]];
        [s appendString:[NSString stringWithFormat:@"<value xsi:type=\"xsd:string\">%@</value>",[[items objectAtIndex:cnt] objectForKey:@"Value"]]];
        [s appendString:@"</item>"];
    }

    // Closing tag
    [s appendString:@"</filter>"];

    NSLog(@"%@",s);
    return s;
}

-(NSMutableString *)prepareComplexFilter:(NSMutableArray *)items
{
    // Prepare args string
    NSMutableString *s = [NSMutableString string];
    [s appendString:[NSString stringWithFormat:@"<complex_filter SOAP-ENC:arrayType=\"ns1:complexFilter[%d]\" xsi:type=\"ns1:complexFilterArray\">", items.count]];

    // Add complex filter
    for (int cnt=0; cnt<items.count; cnt++)
    {
        [s appendString:@"<item xsi:type=\"ns1:complexFilter\">"];
        [s appendString:[NSString stringWithFormat:@"<key xsi:type=\"xsd:string\">%@</key>",[[items objectAtIndex:cnt] objectForKey:@"Key"]]];
        [s appendString:@"<value xsi:type=\"ns1:associativeEntity\">"];
        [s appendString:[NSString stringWithFormat:@"<key xsi:type=\"xsd:string\">%@</key>",[[items objectAtIndex:cnt] objectForKey:@"Operator"]]];
        [s appendString:[NSString stringWithFormat:@"<value xsi:type=\"xsd:string\">%@</value>",[[items objectAtIndex:cnt] objectForKey:@"Value"]]];
        [s appendString:@"</value>"];
        [s appendString:@"</item>"];
    }

    // Closing tag
    [s appendString:@"</complex_filter>"];

    NSLog(@"%@",s);
    return s;
}

Pass required arguments to these functions in this form:

NSMutableArray *ary_filterNormal = [NSMutableArray arrayWithObjects:
                            [NSDictionary dictionaryWithObjectsAndKeys:@"status",@"Key", @"complete",@"Value", nil],
                            nil];

    [service call:self
           action:@selector(callHandler:)
        sessionId:[USERDEFAULTS objectForKey:@"SESSION"]
     resourcePath:@"sales_order.list"
             args:[self prepareFilter:ary_filterNormal]];

So basically just prepare the structure of the request and pass it to the args: for filtering.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM