我正在尝试创建具有两个单独变体的产品。我已经更改了标准代码,所以我的变体下拉菜单看起来像这样:
<div id="product-variants" class="col-md-6">
<h3 class="product-section-title">Colour options</h3>
<ul class="list-group">
<li>
<%= select_tag "variant_id", options_for_select(@product.variants_and_option_values(current_currency).collect{|v| ["#{variant_options(v)}", v.id]})%>
</li>
</ul>
</div>
我的问题是我想要创建两个单独的选项类型 - 外部颜色和内部颜色。目前,如果我添加更多变种,只需将它们添加到同一个下拉菜单中,但我希望将这两个选项分开。
基本上我要求的是如何区分这两者。像 -
这样的东西product.variants.select do |v|
v.option_types.include? Spree::OptionValue.find_by_name('Inside')
end
提前致谢!
答案 0 :(得分:3)
我设法让它运转起来。这是我做的:
<ul class="list-group">
<li>
<% outside = @product.variants_and_option_values(current_currency).collect{|v| ["#{variant_options(v)}", v.id] if variant_options(v).include? 'Outside'} %>
<%= select_tag "variant_id", options_for_select(outside.compact)%>
</li>
<li>
<% inside = @product.variants_and_option_values(current_currency).collect{|v| ["#{variant_options(v)}", v.id] if variant_options(v).include? 'Inside'} %>
<%= select_tag "variant_id_inside", options_for_select(inside.compact)%>
</li>
</ul>