使用Spree,如何在Rails控制台中从订单中查找产品选项值? [英] Using Spree, how can I find product option values from an order in rails console?
问题描述
我能够从订单中获取产品,但是我仍然没有找到获取其option_values来生产产品的方法。这是我找到产品的方式:
I am able to get products from an order, but I still didn't find a way to get its option_values in order to produce it. This is how I found the product:
p = Order.find_by_number("R326153622").products.first
然后,我通过 p.option_types
获得了option_types我:
Then, I have its option_types through p.option_types
which gives me:
=> [#<OptionType id: 935339118, name: "gender", ...>,
#<OptionType id: 935339117, name: "size", ...>,
#<OptionType id: 643188970, name: "color", ...>]
好!现在我的头痛开始了。我只是不知道客户在将其放入购物车时选择的产品的性别,尺寸和颜色的位置。
Ok! Now my headache starts. I just can't realize where to find the gender, size, and color of this product, chosen by the customer when he put it in his cart.
我正在放弃并立即致电客户,但仍想了解它= D
I'm giving up and calling the customer right away, but still wanted to understand it =D
推荐答案
您可以这样做
p = Order.find_by_number("R326153622").products.first
然后
p.option_types.map(&:name)
是什么这里发生的是这种形式
what is happening here is that this form
array.map(&:method_name)
在每个数组成员上调用此方法
call this methods on each one of array members
这篇关于使用Spree,如何在Rails控制台中从订单中查找产品选项值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!