问题
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
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.
I'm giving up and calling the customer right away, but still wanted to understand it =D
回答1:
you can do it like so
p = Order.find_by_number("R326153622").products.first
then
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
来源:https://stackoverflow.com/questions/16240226/using-spree-how-can-i-find-product-option-values-from-an-order-in-rails-console