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

which creates the post params
{"utf8"=>"✓",

"authenticity_token"=>"VT22Qr0uN9Xs/sBexRlWeC9t/0O6Uzle2RL4MUcP3nQ=",
"products"=>{"1060500597"=>"1013589420"},
"quantity"=>{"1013589418"=>"1",
"1013589419"=>"1",
"1013589420"=>"1"}}

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
error

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...
right?
if populator.populate(params.slice(:products, :variants, :quantity))
(from
https://github.com/spree/spree/blob/master/core/app/controllers/spree/orders_controller.rb#L44)

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
@product.variants.active.each_with_index do |v,index|
next if v.option_values.empty? || (!v.in_stock &&
!Spree::Config[:show_zero_stock_products])
checked = !has_checked && (v.in_stock ||
Spree::Config[:allow_backorders])
has_checked = true if checked %>
<li>

<label for="<%= ['products', @product.id, v.id].join('_')
%>">
<span class="variant-description">
<%= variant_options v %> <%= text_field_tag
(@product.has_variants? ? :quantity : "variants[#{@product.master.id}]"),1,
:class => "title", :size => 3 %>
</span>
<% if variant_price_diff v %>
<span class="price diff"><%=
variant_price_diff v %></span>
<% end %>
</label>
</li>
<% 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 @
categoriesrubyonrails
postedJan 18, '13 at 8:18a
activeJan 18, '13 at 8:18a
posts1
users1
websitespreecommerce.com
irc#RubyOnRails

1 user in discussion

Roland Shoemaker: 1 post

People

Translate

site design / logo © 2023 Grokbase