狂欢-在同一页面上将多个变体添加到购物车 [英] Spree - Adding multiple variants to cart on the same page

查看:83
本文介绍了狂欢-在同一页面上将多个变体添加到购物车的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将Spree用于一个电子商务网站,将要出售的每种产品都有多种颜色,并且大多数客户会希望购买同一产品的不同颜色(例如,变体)。我希望允许客户在同一页面上添加同一产品的多个变体,我目前有一个带有单选按钮的变体列表,该单选按钮允许选择要购买的变体和数量。相反,我只想要一些默认为零的数量框,以便客户可以将他们想要的数量简单地添加到每个变量中,然后单击添加到购物车。在查看了订单控制器之后,我想到了这个

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?

推荐答案

Neeeeeeeevermind,读取了order_populate的模型,没有意识到它使用的是来自产品/变体的两个不同的哈希模型,我试图传递哈希产品,这导致了错误,因为它不希望使用产品哈希来实现哈希,而是使用了使用代码

Neeeeeeeevermind, read the model for order_populate, didn't realize it was using two different hash models from products/variants, I was trying to pass the hash products, which caused the errors because it wasn't expecting a hash with the products hash, instead used a variants hash, using the code

<%= text_field_tag "variants[#{v.id}]",0, :class => "title", :size => 3, :disabled => !v.in_stock && !Spree::Config[:allow_backorders] %>

希望这对其他人有帮助!

Hope this helps other people!

这篇关于狂欢-在同一页面上将多个变体添加到购物车的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆