Answers.Body: <p>Ok you're getting there, but your form syntax is a bit off.  MultiAdd needs you to post a form with an array named items.</p>
  
  <p>Here's an example of precisely the sort of thing you need to post:</p>
  
  <pre><code>action    
  multiAdd/multiAdd
  
  items[1][purchasableId]    
  854
  items[1][qty]    
  0
  
  items[4][purchasableId]    
  857
  items[4][qty]    
  1
  
  items[5][purchasableId]    
  858
  items[5][qty]    
  0
  
  items[6][purchasableId]    
  859
  items[6][qty]    
  1
  
  redirect    
  /cart
  </code></pre>
  
  <p>So you're posting items, each keyed by an index value to keep the attributes together.  This can be anything really.  You just have to send for each the purchasableId and a qty (if you send 0 the item will just be ignored).</p>
  
  <pre><code>items[whatever][purchasableId]
  items[whatever][qty]
  </code></pre>
  
  <p>Just send as many of those pairs as you need, exactly like that (i.e. it must be called <code>items</code>, and the word <code>whatever</code> you can replace with an arbitrary key).  Each pair must have a value for purchasableId and qty (so for the first example the purchasableId is 854 and the qty is 0, so this one won't be added to the cart).</p>
  
  <p>(You don't need to use the options syntax to add products as such, that's only required if you're using options with those products.  Maybe get your form working without options first, so just adding products) and then we can add them if you need them!)</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-02-08T04:00:02.890Z
Answers.LastActivityDate: 2016-02-08T04:16:05.257Z
Answers.LastEditDate: 2016-02-08T04:16:05.257Z
Answers.UserDisplayName: Jeremy Daalder
Body: <p>I am trying (and failing miserably) to send multipule products to my cart using <a href="https://github.com/engram-design/MultiAdd" rel="nofollow">MultiAdd</a></p>
  
  <p>I can see the data getting sent - it looks ok? I get a 200 response back, so I know its working, but I'm always getting this error:</p>
  
  <pre><code>{"error":["No items?"]}
  </code></pre>
  
  <p>Here is what my form data looks like:</p>
  
  <pre><code>action:multiAdd/multiAdd
  redirect:commerce/cart
  qty:1
  CSRF:gQBSJxqkMIQChG3r6TJ4Dz81dgtZuh4yrv_ZUDTp|ecc547c00a45b29a506b9f4c7904e62add62d37a
  myProductOne:174
  myProductTwo:64
  myProductThree:189
  </code></pre>
  
  <p>My product template looks like this:</p>
  
  <pre><code>&lt;form&gt;
  &lt;input type="hidden" name="action" value="multiAdd/multiAdd"&gt;
  ...
  
  &lt;select name="myProductOne"&gt;
      &lt;option value="174"&gt;Value&lt;/option&gt;
  &lt;/select&gt;
  ...
  &lt;select name="myProductTwo"&gt;
      &lt;option value="64"&gt;Value&lt;/option&gt;
  &lt;/select&gt;
  ...
  &lt;select name="myProductTwo"&gt;
      &lt;option value="189"&gt;Value&lt;/option&gt;
  &lt;/select&gt;
  </code></pre>
  
  <p>I am using jquery validator to validate my form; I'm handling the submit like this:</p>
  
  <pre><code>...
   onFormSubmit(function (response) {
       console.log(response);
   });
  
  
  var onFormFormSubmit = function (callback) {
      var data = $('#campRegistrationForm').serialize();
      data['CSRF'] = $('input[name="CSRF"]').val();
  
      $.ajax({
          'type': 'post',
          'contentType': 'application/x-www-form-urlencoded; charset=UTF-8',
          'cache': false,
          'data': data,
          'url': '/actions/' + $('input[name="action"]').val(),
          'dataType': 'json',
          'timeout': 50000
      }).done(function (response) {
          callback(response);
      }).fail(function (error) {
          // Total fail.
      });
  };
  </code></pre>
  
  <p>I see on the plugin's page, I need to have markup like this:</p>
  
  <pre><code>&lt;select name="items[{{ loop.index }}][options][color]"&gt;
  </code></pre>
  
  <p>I believe it all boils down to the fact I'm not doing this correctly:</p>
  
  <pre><code>{% for product in craft.commerce.products.find() %}
  ...
  {% endfor %}
  </code></pre>
  
  <p>Since I am selling 3-5 different products on any given page, I can't loop through <em>all</em> of my products as I only need specific ones at any given time. I'm not sure how to set that up correctly.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Thank you so much!</p>
  
  <p>To help others, here is what each of my select input(s) look like:</p>
  
  <pre><code>&lt;select id="myProductOne" name="items[1][purchasableId]"&gt;
  &lt;input type="hidden" name="items[1][qty]" value="1"&gt;
  ...
  &lt;select id="myProductTwo" name="items[2][purchasableId]"&gt;
  &lt;input type="hidden" name="items[2][qty]" value="1"&gt;
  
  ...
  </code></pre>
  
Tags: <plugin-development><plugin-craftcommerce>
Title: Why does MultiAdd think I am not sending any items?
ThreadText: # Why does MultiAdd think I am not sending any items?
  
  (Asked by: username_0 on 2016-02-08)
  
  I am trying (and failing miserably) to send multipule products to my cart using [MultiAdd](https://github.com/engram-design/MultiAdd)
  
  I can see the data getting sent - it looks ok? I get a 200 response back, so I know its working, but I'm always getting this error:
  
  ```
  {"error":["No items?"]}
  
  ```
  
  Here is what my form data looks like:
  
  ```
  action:multiAdd/multiAdd
  redirect:commerce/cart
  qty:1
  CSRF:gQBSJxqkMIQChG3r6TJ4Dz81dgtZuh4yrv_ZUDTp|ecc547c00a45b29a506b9f4c7904e62add62d37a
  myProductOne:174
  myProductTwo:64
  myProductThree:189
  
  ```
  
  My product template looks like this:
  
  ```
  <form>
  <input type="hidden" name="action" value="multiAdd/multiAdd">
  ...
  
  <select name="myProductOne">
      <option value="174">Value</option>
  </select>
  ...
  <select name="myProductTwo">
      <option value="64">Value</option>
  </select>
  ...
  <select name="myProductTwo">
      <option value="189">Value</option>
  </select>
  
  ```
  
  I am using jquery validator to validate my form; I'm handling the submit like this:
  
  ```
  ...
   onFormSubmit(function (response) {
       console.log(response);
   });
  
  var onFormFormSubmit = function (callback) {
      var data = $('#campRegistrationForm').serialize();
      data['CSRF'] = $('input[name="CSRF"]').val();
  
      $.ajax({
          'type': 'post',
          'contentType': 'application/x-www-form-urlencoded; charset=UTF-8',
          'cache': false,
          'data': data,
          'url': '/actions/' + $('input[name="action"]').val(),
          'dataType': 'json',
          'timeout': 50000
      }).done(function (response) {
          callback(response);
      }).fail(function (error) {
          // Total fail.
      });
  };
  
  ```
  
  I see on the plugin's page, I need to have markup like this:
  
  ```
  <select name="items[{{ loop.index }}][options][color]">
  
  ```
  
  I believe it all boils down to the fact I'm not doing this correctly:
  
  ```
  {% for product in craft.commerce.products.find() %}
  ...
  {% endfor %}
  
  ```
  
  Since I am selling 3-5 different products on any given page, I can't loop through *all* of my products as I only need specific ones at any given time. I'm not sure how to set that up correctly.
  
  **EDIT**
  
  Thank you so much!
  
  To help others, here is what each of my select input(s) look like:
  
  ```
  <select id="myProductOne" name="items[1][purchasableId]">
  <input type="hidden" name="items[1][qty]" value="1">
  ...
  <select id="myProductTwo" name="items[2][purchasableId]">
  <input type="hidden" name="items[2][qty]" value="1">
  
  ...
  
  ```
  
  **Tags:** plugin-development, plugin-craftcommerce
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2016-02-08. Score: 2 | Accepted answer
  
  Ok you're getting there, but your form syntax is a bit off. MultiAdd needs you to post a form with an array named items.
  
  Here's an example of precisely the sort of thing you need to post:
  
  ```
  action    
  multiAdd/multiAdd
  
  items[1][purchasableId]    
  854
  items[1][qty]    
  0
  
  items[4][purchasableId]    
  857
  items[4][qty]    
  1
  
  items[5][purchasableId]    
  858
  items[5][qty]    
  0
  
  items[6][purchasableId]    
  859
  items[6][qty]    
  1
  
  redirect    
  /cart
  
  ```
  
  So you're posting items, each keyed by an index value to keep the attributes together. This can be anything really. You just have to send for each the purchasableId and a qty (if you send 0 the item will just be ignored).
  
  ```
  items[whatever][purchasableId]
  items[whatever][qty]
  
  ```
  
  Just send as many of those pairs as you need, exactly like that (i.e. it must be called `items`, and the word `whatever` you can replace with an arbitrary key). Each pair must have a value for purchasableId and qty (so for the first example the purchasableId is 854 and the qty is 0, so this one won't be added to the cart).
  
  (You don't need to use the options syntax to add products as such, that's only required if you're using options with those products. Maybe get your form working without options first, so just adding products) and then we can add them if you need them!)
  
  
  ---
  
  