【问题标题】:spree get variant option value大礼包获取变体选项值
【发布时间】:2015-11-03 14:29:02
【问题描述】:

我创建了产品及其变体。变体有尺寸和颜色可供选择。

我正在尝试阅读所有变体及其颜色名称:

variants = product.variants_including_master.active(current_currency).includes([:option_values])

variants.each do |variant|
  # here I want to read variant options color and size
  # something like:  variant.option_values['color']
end

我在网上看到了很多东西,但什么都买不到。

【问题讨论】:

    标签: product spree variant


    【解决方案1】:

    我用这个解决了我的问题:

          variants = product.variants_including_master.active(current_currency).includes([:option_values])
    
          variants.each do |variant|
    
            color = variant.option_values.select { |a| a.option_type.id == 2 }.first
    
            if not color.nil? then
              @product_colors << color[:name]
            end
          end
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-04
      • 2023-03-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多