0

In my app I've to create a structure like this:

$arrProducts = array(
    array(
        “product_id” => “1”,
        “qty” => 2
                "options" => array(         
                    optionId_1 => optionValue_1,
                    ...,
                    optionId_n => optionValue_n
                 )

I did this array of array so:

NSDictionary *dict = @{
       @"product_id" : productID,
       @"qty": self.qty
   };
NSArray *array2 = @[dict];

This array should work with a Magento store, when I run the app it shows me this message:

error cart_product.add: SQLSTATE[21000]: Cardinality violation: 1241 Operand should contain 1 column(s)

I guess this problem, depends on how I create this array, but I'm not understanding what's wrong with this array, can you help me to fix it?

UPDATE:

The library I'm using to connect to Magento needs this structure:

[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);
}];

I will use it to add a product into a cart if you take a look in Magento SOAP API to add a product to cart you can see that in phpthey add product by using an array of an array. I need to replicate the same structure.

2
  • Did you consider using a dictionary, as it seems to be more like a key/value based structure. Commented Nov 18, 2013 at 10:25
  • I need to do a stuff like this, because the library I'm using to connect to Magento needs the structure I will show you in my question Commented Nov 18, 2013 at 10:30

1 Answer 1

1

First, you put an NSDictionary in an array, and after that you do it again. That's wrong. Do it like this:

NSDictionary *product1 = @{@"product_id" : productID, @"qty": self.qty, "options" : @{optionId_n : optionValue_n}};
NSDictionary *product2 = @{@"product_id" : productID, @"qty": self.qty, "options" : @{optionId_n : optionValue_n}};
NSArray *products = @[product1, product2];
Sign up to request clarification or add additional context in comments.

2 Comments

It's not the same I did in my code? I will add only one product, so I guessed I've to create a single NSDictionary and then I need to put this NSDictionary in an NSArray
I tried it and it doesn't work... It gives me the same error: error SQLSTATE[21000]: Cardinality violation: 1241 Operand should contain 1 column(s)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.