title: Adding multiple products to cart in Spree store (Rails 4.2.5.2 / Spree 3.1.0)
body: <p>I'm trying to create a section on the Product show page that will display 3 products, with checkboxes beneath them, and a button to add the selected ones to the cart. As I have it now, only the last item is being added to the cart, I believe because the multiple variables with the same name are being used, and only the last one is selected (as discussed <a href="https://stackoverflow.com/questions/18288123/spree-ruby-on-rails-add-to-cart-multiple-variants-of-the-same-product">here</a>). </p>
  
  <p>The answer linked above is for Spree 2.0.4, and I'm using 3.1.0, so I can't quite use the answer as discussed there.</p>
  
  <p>I have looked into the Spree API, as discussed in <a href="https://stackoverflow.com/questions/30941045/adding-multiple-products-to-spree-cart-with-single-click">this</a> question (and also using Rails 4 and Spree 3, so much closer to the versions I need). But there is no answer, just a comment saying "use the api" and no discussion on how to do so.</p>
  
  <p>Another <a href="https://stackoverflow.com/questions/33202564/spree-how-to-add-multiple-products-to-cart">answer</a> suggested using Spree Promotions, but I don't think that's what I need.</p>
  
  <p>(This <a href="https://stackoverflow.com/questions/14353161/spree-adding-multiple-variants-to-cart-on-the-same-page">other</a> answer was using Rails 3.2, and I couldn't find the model <code>order_populate</code> they referenced.)</p>
  
  <p>Here is my code:</p>
  
  <pre><code>&lt;%= form_for :order, url: populate_orders_path do |f| %&gt;
    &lt;!-- placeholder; select actual products later --&gt;
    &lt;% Spree::Product.all.take(3).each_with_index do |product, index| %&gt;
      &lt;% if product.can_supply? %&gt;
        &lt;%= render partial: 'spree/products/product', locals: { product: product } %&gt;
        &lt;%= hidden_field_tag "variant_id", product.master.can_supply? ? product.master.id : product.variants.find(&amp;:can_supply?).id %&gt;
        &lt;!-- placeholder; replace with checkbox after hardcoded quantity working --&gt;
        &lt;%= hidden_field_tag :quantity, 1 %&gt;
        &lt;%#= check_box "quantity", product.master.id, { class: "similar-product-checkbox" } %&gt;
      &lt;% end %&gt;
    &lt;% end %&gt;
  
    &lt;span class="input-group-btn"&gt;
      &lt;%= button_tag class: 'btn btn-success primary-cta', id: 'add-pairings-to-cart-button', type: :submit do %&gt;
      &lt;%= Spree.t(:add_items_to_cart) %&gt;
      &lt;% end %&gt;
    &lt;/span&gt;
  &lt;% end %&gt;
  </code></pre>