title: Shopify jquery ajax api, addItem() returns successfully, but the cart doesn't show the correct number of items
body: <p>I'm attempting to add 3 items to the cart in a loop. Firebug reports each individual ajax call to '/cart/add.js' is returning with a 200 OK, and the json object being returned shows the correct variant_id and quantity that was just added. However, the resulting contents of the cart is usually incorrect - often showing only 1 or 2, rather than the expected 3 items.</p>
  
  <p>Here is my code.</p>
  
  <pre><code>$('form[name="one-step-checkout"]').submit(function(event) {
    event.preventDefault();
    Shopify.clear(function(cart) {
      add_items(function() {
        Shopify.getCart(function(cart) {
          alert('items in cart : ' + cart.items.length)
        })
      });
    });
  
  });
  
  
  add_items = function(callback) {
    add_variant_array = [];
    $('form[name="one-step-checkout"]').find('div.checkout-step-options input:radio').each(function() {
      if($(this).is(':checked') &amp;&amp; $(this).attr('name') == 'price') {
        var choice = $(this).val();
        $('input.variant-price.' + choice).each(function() {
          var variant_id = this.id;
          add_variant_array.push(Shopify.addItem(variant_id, 1));
        });
      }
  
    });
  
    if (typeof callback == "function") {
      $.when.apply($, add_variant_array).done(function() {
        alert('done adding to cart');
      });
      callback();
    }  
  };
  </code></pre>
  
  <p>If I repeatedly submit the form, the number of items in the cart varies between 1 and 3. The only thing I can think of is that the cart is somehow being cleared in the middle of the operation. I thought the callback being passed to the Shopify.clear() function was't executed until after a success was received? no?</p>
  
  <p>many thanks in advance for any pointers!</p>