So I've changed my code a bit, now using
<%= hidden_field_tag "products[#{}]", %>
<%= text_field_tag "quantity[#{}]",0, :class => "title", :size =>
3, :disabled => !v.in_stock && !Spree::Config[:allow_backorders] %>

which creates the post params


which looks about right, except of course the only one product id, but I
can fix that, the problem I'm running into though is that spree throws the

undefined method `to_i' for {"1013589418"=>"1", "1013589419"=>"1", "1013589420"=>"1"}:ActiveSupport::HashWithIndifferentAccess

which doesn't make sense since the docs show this should be possible...
if populator.populate(params.slice(:products, :variants, :quantity))

What am I missing? or is this a spree bug...

On Wednesday, January 16, 2013 1:10:03 AM UTC-8, Roland Shoemaker wrote:

I'm using Spree for a ecommerece site, each product that will be sold
comes in a large number of colors and most customers will want to purchase
different colors of the same product (e.g. variants). I want customers to
be allowed to add multiple variants of the same product on the same page, I
currently have a list of variants with a radio button that allows a choice
of variant and quantity to be purchased. Instead I just want a number of
quantity boxes that default to zero so the customer can simply add the
number they want to each variant and click add to cart. After looking at
the orders controller I came up with this

<% has_checked = false do |v,index|
next if v.option_values.empty? || (!v.in_stock &&
checked = !has_checked && (v.in_stock ||
has_checked = true if checked %>

<label for="<%= ['products',,].join('_')
<span class="variant-description">
<%= variant_options v %> <%= text_field_tag
(@product.has_variants? ? :quantity : "variants[#{}]"),1,
:class => "title", :size => 3 %>
<% if variant_price_diff v %>
<span class="price diff"><%=
variant_price_diff v %></span>
<% end %>
<% end%>

It works in the sense that it shows what I want, a list of variants and
quantity boxes, but whenever I add quantities and add them to the cart it
just defaults to the last item on the list and the quantity in the last
quantity box. I've tried a few things but none have correctly, Does anyone
know how I would go about doing this?

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupspree-user @
postedJan 18, '13 at 8:18a
activeJan 18, '13 at 8:18a

1 user in discussion

Roland Shoemaker: 1 post



site design / logo © 2023 Grokbase